3 回答

TA貢獻1831條經驗 獲得超10個贊
1. 如果樓主想要使用UINavigationController中的view controller stack,并且還想要同時自定義push、pop的動畫效果,基本上是不可能的。原因在于想要使用view controller stack,就無法躲開
pushViewController:animated:這個方法,而一旦使用pushViewController:animated:,UINavigationController就會強制將要推入的viewController的frame設為當前可視區域的frame,從而斷絕一切想要自定義動畫的后路,例如如下代碼,是不會產生任何效果的:
UINavigationController+CustomAnimation.h
@interface UINavigationController (CustomAnimation)- (void)customPushViewController:(UIViewController *)viewController;@end
UINavigationController+CustomAnimation.m
#import "UINavigationController+CustomAnimation.h"- (void)customPushViewController:(UIViewController *)viewController { viewController.view.frame = (CGRect){0, -viewController.view.frame.size.height, viewController.view.frame.size}; [self pushViewController:viewController animated:NO]; [UIView animateWithDuration:.15f animations:^{ viewController.view.frame = (CGRect){0, 0, self.view.bounds.size}; }]; }
2. 如果僅僅是想添加自定義的push、pop動畫,而不使用view controller stack,那么,如下代碼就可以實現一個從上到下的push效果:
UINavigationController+CustomAnimation.h文件同上。
UINavigationController+CustomAnimation.m
#import "UINavigationController+CustomAnimation.h"- (void)customPushViewController:(UIViewController *)viewController { viewController.view.frame = (CGRect){0, -viewController.view.frame.size.height, viewController.view.frame.size}; [self.topViewController.view addSubview:viewController.view]; [UIView animateWithDuration:.15f animations:^{ viewController.view.frame = (CGRect){0, 0, self.view.bounds.size}; }]; }

TA貢獻2003條經驗 獲得超2個贊
雖然基于navctrl,但是你可以不用navctrl push的方法,可以用viewctrl的presentModalViewController。至于速度的話,這些系統的默認都是0.3s,動畫方式也就是系統默認的幾個。

TA貢獻1772條經驗 獲得超5個贊
CATransition* transition = [CATransition animation];
transition.type = kCATransitionPush;//可更改為其他方式
transition.subtype = kCATransitionFromLeft;//可更改為其他方式
transition.duration=0.15;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController pushViewController:viewController animated:YES];
- 3 回答
- 0 關注
- 189 瀏覽
添加回答
舉報