界面跳转

  1. 模态跳转(Modal)
    普通的视图控制器一般只有模态跳转的功能,这个方法是所有视图控制器对象都可以用的。
-(void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion
  • 一般跳转前和跳转后的界面通过delegate进行数据交换。
  • 控制器的中的只读属性:presentedViewControllerpresentingViewController,他们分别就是被present的控制器和正在presenting的控制器。
  • 通过 dismissViewControllerAnimated 来返回前一个界面的。
  1. 通过Segue来跳转
    Segue:多出现于UIStoryboard中,是不同类之间跳转的一根线。换种说法就是:Storyboard上每一根用来界面跳转的线,都是一个UIStoryboardSegue对象

Segue

跳转步骤:

  • 创建一个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;
  • 调用
-(void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender
  • 系统在跳转前自动调用
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  segue.sourceViewController;
  segue.destinationViewController;
}

  1. 通过NavigationController跳转
[self pushViewController:.. animated:YES];
[self hidesBottomBarWhenPushed];
  1. UITabBarController
self.selectedItem = 1;

如何从Storyboard中创建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) {

}];

跳转时的动画效果

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]; 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 前言:苹果官方是推荐我们将所有的UI都使用Storyboard去搭建,Storyboard也是一个很成熟的工具了。...
    4d49353c3819阅读 508评论 1 2
  • 前言:苹果官方是推荐我们将所有的UI都使用Storyboard去搭建,Storyboard也是一个很成熟的工具了。...
    Hanfank阅读 6,512评论 7 11
  • 1.自定义控件 a.继承某个控件 b.重写initWithFrame方法可以设置一些它的属性 c.在layouts...
    圍繞的城阅读 3,494评论 2 4
  • 一、前言 1、一个项目中总会有出现界面跳转,常见的就是应用内跳转、Push、Modal、Segue,或者复杂的嵌套...
    gitKong阅读 2,047评论 4 25
  • 参加了朋友女儿满月酒,自己去了,果然没有密不通风的,大家虽然还猜不到谁,但知道了大概。中文她说吃昨天的榴莲太多,今...
    笠翁阅读 187评论 0 0