界面跳轉(zhuǎn)

  1. 模態(tài)跳轉(zhuǎn)(Modal)
    普通的視圖控制器一般只有模態(tài)跳轉(zhuǎn)的功能,這個(gè)方法是所有視圖控制器對象都可以用的。
-(void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion
  • 一般跳轉(zhuǎn)前和跳轉(zhuǎn)后的界面通過delegate進(jìn)行數(shù)據(jù)交換。
  • 控制器的中的只讀屬性:presentedViewControllerpresentingViewController,他們分別就是被present的控制器和正在presenting的控制器。
  • 通過 dismissViewControllerAnimated 來返回前一個(gè)界面的。
  1. 通過Segue來跳轉(zhuǎn)
    Segue:多出現(xiàn)于UIStoryboard中,是不同類之間跳轉(zhuǎn)的一根線。換種說法就是:Storyboard上每一根用來界面跳轉(zhuǎn)的線,都是一個(gè)UIStoryboardSegue對象

Segue

跳轉(zhuǎn)步驟:

  • 創(chuàng)建一個(gè)UIStoryboardSegue對象
+(instancetype)segueWithIdentifier:(nullable NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)destination performHandler:(void (^)(void))performHandler NS_AVAILABLE_IOS(6_0);

or

-(instancetype)initWithIdentifier:(nullable NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)destination NS_DESIGNATED_INITIALIZER;
  • 調(diào)用
-(void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender
  • 系統(tǒng)在跳轉(zhuǎn)前自動調(diào)用
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  segue.sourceViewController;
  segue.destinationViewController;
}

  1. 通過NavigationController跳轉(zhuǎn)
[self pushViewController:.. animated:YES];
[self hidesBottomBarWhenPushed];
  1. UITabBarController
self.selectedItem = 1;

如何從Storyboard中創(chuàng)建ViewController

//通過使用storyborardID去獲取啟動頁viewcontroller
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Launch Screen" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"LaunchScreen"];
UIWindow *mainWindow = [UIApplication sharedApplication].keyWindow;

加載啟動圖

//主界面加載 顯示之前
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self launchAnimation];
}

切換rootViewController

[UIView transitionWithView:weakSelf.window duration:0.8 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{

  BOOL oldState = [UIView areAnimationsEnabled];

  [UIView setAnimationsEnabled:NO];

  [weakSelf.window setRootViewController:nav];

  [UIView setAnimationsEnabled:oldState];

} completion:^(BOOL finished) {

}];

跳轉(zhuǎn)時(shí)的動畫效果

CATransition *animation = [CATransition animation]; [animation setDuration:3.3]; [animation setType:kCATransitionFade]; //淡入淡出 [animation setSubtype:kCATransitionFromLeft]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; MapViewController *mapview = [[MapViewController alloc] initWithNibName:Nil bundle:NULL]; [self.navigationController pushViewController:mapview animated:NO]; [self.navigationController.view.layer addAnimation:animation forKey:nil]; 
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容