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 关注
- 148 浏览
添加回答
举报