首页 > 代码库 > 视图切换的几种方法

视图切换的几种方法

代码:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{    //切换方法1    //动画效果:左右滑动    //必须有导航器视图才能切换    [self.navigationController pushViewController:[[ViewController2 alloc]init] animated:YES];        //切换方法2:    //动画效果:从下滑动到上遮盖住之前的视图,如果有导航栏也被遮盖住了    ViewController2 *controller = [[ViewController2 alloc]init];    [self presentViewController:controller animated:YES completion:NULL];        //切换方法3:    //动画效果:上下的翻动,上下左右的转动,保留导航栏    //必须都是子视图    ViewController2 *controller1 = [[ViewController2 alloc]init];    ViewController2 *controller2 = [[ViewController2 alloc]init];    [self addChildViewController:controller1];    [self.view addSubview:controller1.view];    [self addChildViewController:controller2];    [self.view addSubview:controller2.view];                [self transitionFromViewController:controller1                      toViewController:controller2                              duration:1                               options:UIViewAnimationOptionTransitionCurlDown                            animations:^{}                            completion:^(BOOL finished) {}];}

 

视图切换的几种方法