iOS的7变化pushviewcontroller动画方向 [英] iOS 7 change pushviewcontroller animation direction
问题描述
当我推的ViewController动画始终是从右到左。我想该动画改变到从左到右的倒数。
我已经试过这code,但不工作。动画仍然是从右到左。我怎么能简单地和正确地achive呢?需要帮助,请。先谢谢了。
//不工作
myViewController * mController = [self.storyboard instantiateViewControllerWithIdentifier:@myViewController];CATransition *跃迁= [CATransition动画]
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;[self.view.layer addAnimation:过渡forKey:无];[self.navigationController pushViewController:mController动画:是];
您实际上这样做是正确的,但据我从你的code明白了,你是不是覆盖方法:
- (无效)pushViewController:(UIViewController的*)的viewController动画:(BOOL)动画
所以,你需要从的UINavigationController
继承并覆盖上述方法。
下面是我如何做到这一点(推+ POP):
按
- (无效)pushViewController:(UIViewController的*)的viewController动画:(BOOL)动画{
UIView的* theWindow = self.view;
如果(动画){
CATransition *动画= [CATransition动画]
[动画setDuration:0.45f];
[动画的setType:kCATransitionPush];
[动画setSubtype:kCATransitionFromLeft];
[动画setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[theWindow层] addAnimation:动画forKey:@];
} //确保我们通过超级动画:NO,否则我们会得到我们两个
//动画和超级动画
[超级pushViewController:动画的viewController:NO]; [个体经营swapButtonsForViewController:的viewController];}
流行:
- (UIViewController的*)popViewControllerAnimated:动画(BOOL){
UIView的* theWindow = self.view;
如果(动画){
CATransition *动画= [CATransition动画]
[动画setDuration:0.45f];
[动画的setType:kCATransitionPush];
[动画setSubtype:kCATransitionFromRight];
[动画setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[theWindow层] addAnimation:动画forKey:@];
}
返回[超级popViewControllerAnimated:NO];
}
When i push a viewcontroller the animation is always from right to left. I want to change that animation to the inverse left to right. I have tried this code but doesnt work. The animation is still from right to left. How can i achive this simply and correctly? Need help please. Thanks in advance.
//NOT WORKING
myViewController *mController = [self.storyboard instantiateViewControllerWithIdentifier:@"myViewController"];
CATransition *transition = [CATransition animation];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:mController animated:YES];
You are actually doing it right, but as far as I understand from your code, you are not overriding the method:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
So, you need to inherit from UINavigationController
and override the above method.
Here's how I do it (push + pop):
Push:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
UIView *theWindow = self.view ;
if( animated ) {
CATransition *animation = [CATransition animation];
[animation setDuration:0.45f];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@""];
}
//make sure we pass the super "animated:NO" or we will get both our
//animation and the super's animation
[super pushViewController:viewController animated:NO];
[self swapButtonsForViewController:viewController];
}
Pop :
- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
UIView *theWindow = self.view ;
if( animated ) {
CATransition *animation = [CATransition animation];
[animation setDuration:0.45f];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@""];
}
return [super popViewControllerAnimated:NO];
}
这篇关于iOS的7变化pushviewcontroller动画方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!