0

当用户按下uiviewcontroller导航栏的默认后退按钮(不是自定义按钮)时,我试图产生一个自定义效果。我试图将视图移到某个Y位置,然后弹出视图并让视图控制器消失。按下后退按钮时的自定义动画 - iOS

我尝试了两种方法:

方法1

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 

    [UIView animateWithDuration:0.2 animations:^{ 
    self.cvCell.frame = self.selectedCellFrame; 
    } completion:^(BOOL finished) { 
    [UIView animateWithDuration:0.75 
        animations:^{ 

         [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
         [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.navigationController.view cache:NO]; 
        } completion:^(BOOL finished) { 

         [self.navigationController popViewControllerAnimated:NO]; 
        }]; 
    }]; 


} 

方法2

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ 


if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) { 

    [UIView animateWithDuration:0.2 animations:^{ 
     self.cvCell.frame = self.selectedCellFrame; 
    } completion:^(BOOL finished) { 
     CATransition *transition = [CATransition animation]; 
     [transition setDuration:0.75]; 
     [transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
     [transition setType:kCATransitionReveal]; 
     [transition setSubtype:kCATransitionFromLeft]; 
     [transition setDelegate:self]; 
     [self.navigationController.view.layer addAnimation:transition forKey:nil]; 
    }]; 
    } 
} 

在这两种情况下,视图上的UIView动画会踢之前就消失in。 关于实现这个的任何建议?

回答

0

如果您在iOS应用程序中使用Storyboard,则可尝试实施cusom segue动画。您可以覆盖方法prepareForSegue:sender:来检查事务是否应该发生,方法perform:将屏幕上的新视图控制器。然后,您可以继承UIStoryboardSegue并启用自定义动画在那里
iOS Docs

+0

我试图弹出从B.视图控制器A I登陆b。在使用自定义动画赛格瑞(我使用了一个故事板)。我是否应该创建另一个自定义segue来弹出此视图控制器? – 2015-04-04 05:56:03

+0

是的,如果它自动返回,它可能还需要重新配置“后退”按钮。查看后'prepareForSegue:发件人:'只适用于前进方向,向后移动使用'prepareForUnwind:发件人:'更多信息请点击: [http://spin.atomicobject.com/2014/12/ 01 /程序-IOS退绕-SEGUE /(http://spin.atomicobject.com/2014/12/01/program-ios-unwind-segue/) – 2015-04-05 15:38:07