代码改变世界

ios中在uiNavigationcontroller中做转场动画

2013-07-14 18:12  甘超波  阅读(3214)  评论(0编辑  收藏  举报

1:了解,当创建一个UINavigationcontroller中时,当创建一个子视图控制器压入uiNavigationController中,其中里面的view也别加入UINavigationcontoller.view中去了

验证代码

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
      [self digui:self.navigationController.view];
     NSLog(@"2.1-->%p",self.view.superview);
}

-(void)digui:(UIView *)view{
    for (UIView *child in view.subviews) {
        NSLog(@"---%p",child);
        [self digui:child];
    }
    
}

 

转场动画第一种方式

-(void)click{
    
    MyViewController *my=[[MyViewController alloc] init];
    [self.navigationController pushViewController:my animated:NO];
     //因为一个事件循环机制中
    CATransition *tran=[CATransition animation];
    tran.duration=0.75;
    tran.type=@"cameraIrisHollowOpen";
    tran.subtype=kCATransitionFromLeft;
    [self.navigationController.view.layer addAnimation:tran forKey:nil];
}

转场动画第二种方式

-(void)click{
    
    
    [UIView transitionWithView:self.navigationController.view duration:0.5 options:UIViewAnimationOptionTransitionCurlUp animations:^{
        MyViewController *my=[[MyViewController alloc] init];
        [self.navigationController pushViewController:my animated:NO];
    } completion:^(BOOL finished) {
        
    }];
    
 
 
}

转场动画第三种方式

-(void)click{

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view  cache:YES];
    MyViewController *my=[[MyViewController alloc] init];
   [self.navigationController pushViewController:my animated:NO];
    [UIView commitAnimations];
    }