iPhone - UINavigationController - custom animation with CATransaction

对着背影说爱祢 提交于 2019-12-03 20:34:30

I've accomplished something similar, though I didn't bother to move it into it's own function:

CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition forKey:nil];

[self.navigationController popViewControllerAnimated:NO]

You could abstract it out. Using your code, it would look like:

- (void)popViewControllerMoveInFromTop {
[CATransaction begin];
CATransition *transition;
transition = [CATransition animation];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromTop;
transition.duration = 0.7;

[CATransaction setValue:(id)kCFBooleanTrue
                 forKey:kCATransactionDisableActions];

[self.view.layer addAnimation:transition forKey:nil];
[self  popViewControllerAnimated:NO];    
[CATransaction commit];
}

You can also create a custom transition for pop using UIView's animations. Here you are applying an animation to the view that's about to disappear and then popping it from the view stack:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO]; 

[self.navigationController popViewControllerAnimated:NO];

[UIView commitAnimations];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!