2016-11-21 71 views
0

我有具有以下結構的應用程序:當前視圖控制器被示

主視圖控制器是具有4個標籤標籤欄視圖控制器。 用戶只能在登錄時訪問這些視圖控制器。當應用程序啓動時,它會加載它的初始視圖控制器(標籤欄一),然後檢查用戶是否已通過身份驗證。如果不是,我會提供一個登錄視圖控制器。

我遇到的問題是,當應用程序啓動時,它加載標籤欄控制器,並從該控制器它呈現登錄視圖控制器,但它與一個小的時間窗口顯示標籤欄控制器的視圖上屏幕,在登錄視圖之前。我需要從標籤欄控制器直接顯示登錄視圖,但不會顯示標籤欄控制器的視圖,因爲它不便於用戶使用。

我讀了一些有關呈現新的視圖控制器沒有動畫,這就是我在做什麼,但仍然存在問題的stackoverflow上的答案。

我希望我對這個問題已經足夠清楚,如果您需要更多信息,請讓我知道。

編輯:我在applicationDelegate.m

+0

當前登錄視圖控制器或者設置你的'rootviewcontroller' as'tabbarcontroller'或'tabbarcontroller的rootview'後。你不應該在'applicationdidbeactiveactive'中編寫'applicationdidfinish launch'' – Vinodh

+1

發佈你正在使用的代碼我們將折射器和幫助你,沒有代碼我們不能幫你很多 – Vinodh

回答

1

applicationDidBecomeActive:呈現登錄視圖控制器在應用程序的委託,在didFinishLaunchingWithOptions,

在條件如果登錄與否,

self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; 

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 

    UIViewController *viewController =[storyboard instantiateViewControllerWithIdentifier:@"your identifier"]; 

    self.window.rootViewController = viewController; 
    [self.window makeKeyAndVisible]; 
+0

@Gustavo Amgarten如果你覺得這有幫助,那麼請接受這個答案讓其他人很容易找到這個。 – KAR

+0

問題在於我想讓我的根視圖控制器成爲標籤欄控制器,並從該控制器提供登錄控制器。原因是我想只在用戶身份驗證成功時關閉登錄視圖控制器 –

+0

您是使用storyboard還是通過代碼來設置tabbarcontroller? – Vinodh

1

你在故事板中有視圖控制器時應該這樣。

self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; 

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 

FirstViewController *firstviewController = [storyboard instantiateViewControllerWithIdentifier:@"FirstViewController"]; 
SecondViewController *secondviewController = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"]; 

firstviewController.tabBarItem.image = [UIImage imageNamed:@"24-around-7"]; 
firstviewController.tabBarItem.title = @"First"; 
secondviewController.tabBarItem.title = @"Second"; 
secondviewController.tabBarItem.image = [UIImage imageNamed:@"60-around-7"]; 
UITabBarController *tabBarController = [[UITabBarController alloc]init]; 
tabBarController.viewControllers = @[firstviewController,secondviewController]; 

self.window.rootViewController = tabBarController; 

而且在FirstViewControllerviewDidAppear應檢查用戶登錄或沒有和現在的視圖控制器。

BOOL loginStatus = [[NSUserDefaults standardUserDefaults] boolForKey:@"isLoggedIn"]; 
if(loginStatus == NO){ 

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    LoginViewController *loginViewcontroller = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; 
    [self presentViewController:loginViewcontroller animated:YES completion:nil]; 
} 

成功登錄後只需關閉登錄視圖控制器。如果用戶註銷剛剛呈現loginviewcontroller

0

創建新.H .M

(這是我的代碼)

yourController.h和yourController.m

然後打開

yourcontroller。 m

- (id)initWithFrame:(CGRect)frame 

{ 
    self = [super initWithFrame:frame]; 
if (self) 
{ 
    NSLog(@"initWithFrame"); 

    [self setupPinPopUp]; 
} 
return self; 
} 

-(void)setupPinPopUp{ 

UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; 
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; 
blurEffectView.frame = CGRectMake(0, 66, kSCREEN_WIDTH, kSCREEN_HEIGHT-66); 
blurEffectView.userInteractionEnabled = TRUE; 

UITapGestureRecognizer *singleFingerTap = 
[[UITapGestureRecognizer alloc] initWithTarget:self 
             action:@selector(handleSingleTap:)]; 
[blurEffectView addGestureRecognizer:singleFingerTap]; 

blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
[self addSubview:blurEffectView]; 

UIView *popUpMainView = [[UIView alloc]initWithFrame:CGRectMake(kSCREEN_WIDTH/2-150, kSCREEN_HEIGHT/2-160, 300, 270)]; 
popUpMainView.backgroundColor = Clear; 
[self addSubview:popUpMainView]; 


UIView *popUpInsideView = [[UIView alloc]initWithFrame:CGRectMake(kSCREEN_WIDTH/2-150, kSCREEN_HEIGHT/2-102, 300, 210)]; 
popUpInsideView.backgroundColor = White; 
popUpInsideView.layer.cornerRadius = 2.0; 
popUpInsideView.clipsToBounds = TRUE; 
[self addSubview:popUpInsideView]; 


UIImageView *imgCircleView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 0, 100, 100)]; 
imgCircleView.layer.cornerRadius = 50; 
imgCircleView.backgroundColor = White; 
imgCircleView.clipsToBounds = TRUE; 
[popUpMainView addSubview:imgCircleView]; 


UIImageView *imgInnerCircleView = [[UIImageView alloc]initWithFrame:CGRectMake(25, 8, 50, 50)]; 
imgInnerCircleView.backgroundColor = Clear; 
imgInnerCircleView.image = [UIImage imageNamed:@"support"]; 
[imgCircleView addSubview:imgInnerCircleView]; 


UILabel *lblHeading = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, popUpMainView.frame.size.width, 45)]; 
lblHeading.text = @"CUSTOMER SUPPORT"; 
lblHeading.numberOfLines = 0; 
lblHeading.textColor = Black; 
lblHeading.textAlignment = NSTextAlignmentCenter; 
lblHeading.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:21]; 
[popUpInsideView addSubview:lblHeading]; 


    UIButton *btnPhoneNumber = [[UIButton alloc]initWithFrame:CGRectMake(0, lblHeading.frame.size.height+lblHeading.frame.origin.y+10, popUpMainView.frame.size.width, 45)]; 
    [btnPhoneNumber setTitle:@"18002345678" forState:UIControlStateNormal]; 
    [btnPhoneNumber setTitleColor:Black forState:UIControlStateNormal]; 
    btnPhoneNumber.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 
    btnPhoneNumber.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:18]; 
    [btnPhoneNumber addTarget:self action:@selector(callSupport:) forControlEvents:UIControlEventTouchUpInside]; 
    [popUpInsideView addSubview:btnPhoneNumber]; 


UIButton *btnEmail = [[UIButton alloc]initWithFrame:CGRectMake(0, btnPhoneNumber.frame.size.height+btnPhoneNumber.frame.origin.y+10, popUpMainView.frame.size.width, 45)]; 
[btnEmail setTitle:@"[email protected]" forState:UIControlStateNormal]; 
[btnEmail setTitleColor:Black forState:UIControlStateNormal]; 
btnEmail.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 
btnEmail.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:18]; 
[btnEmail addTarget:self action:@selector(emailSupport:) forControlEvents:UIControlEventTouchUpInside]; 
[popUpInsideView addSubview:btnEmail]; 

} 

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer { 

[self removeFromSuperview]; 

} 


-(IBAction)callSupport:(id)sender{ 

NSString *phoneNumber = [@"tel://" stringByAppendingString:@"180023456789"]; 
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]]; 


[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber] options:@{} completionHandler:^(BOOL success) 
{ 
if (success) { 
    NSLog(@"Opened url"); 
} 
}]; 

} 


-(IBAction)emailSupport:(id)sender{ 

[self removeFromSuperview]; 
} 

//將方法稱爲thi ŝ無論你想打電話 //在應用程序委託

UIView *rectView; 


- (void)applicationWillEnterForeground:(UIApplication *)application 
{ 


    [rectView removeFromSuperview]; 
    rectView = [[VurifyAppValidation alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_HEIGHT)]; 
[self.window addSubview:rectView]; 
} 
相關問題