新建個UINavigationController的類別:
#import "UINavigationController+CustomAnimation.h"
@implementation UINavigationController (CustomAnimation)
- (void)customPushViewController:(UIViewController *)viewController
{
viewController.view.frame = (CGRect){-viewController.view.frame.size.width, 0, viewController.view.frame.size};
[self.topViewController.view addSubview:viewController.view];
[UIView animateWithDuration:.35f
animations:^{
viewController.view.frame = (CGRect){0, 0, self.view.bounds.size};
}];
}
@end
這種方法是將新的View 加到了self.navigationController.topViewController 上,然後加上了滑動動畫。
使用
- (void)backToHome
{
[UIView beginAnimations:@"popView" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:.5f];
[UIView setAnimationDidStopSelector:@selector(popAnimationDidStop)];
self.view.frame = CGRectMake(-CGRectGetWidth(self.view.frame), 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame));
[UIView commitAnimations];
}
可以作為pop的動畫使用