[英]CATransition for left and right animation in the navigation stack?
I need to call one of two different CATranistion functions (I've created) one which does kCATransitionFromRight and another which does kCATransitionFromLeft, yeah I'll combine the function when I'm done. 我需要调用两个不同的CATranistion函数(已创建)之一,一个执行kCATransitionFromRight,另一个执行kCATransitionFromLeft,是的,我将在完成后合并该函数。
However, I have a view in my navigation stack which is 1 view deep. 但是,我的导航堆栈中有一个视图,深度为1个视图。 Depending on whether you enter or leave the view from the view above or below in the stack, I need to use either left or right.
根据您是进入还是离开堆栈上方或下方的视图,我需要使用向左还是向右。
First view => problem view, transition left.
Problem view => first view, transition right.
Problem view => third view, transition left.
Third view <= problem view, transition right.
I currently call the functions in viewWillAppear. 我目前在viewWillAppear中调用这些函数。
However, I don't know how to tell the function which direction to use. 但是,我不知道如何告诉函数使用哪个方向。
I know I could use an app delegate variable, singleton or nsuserdefault setting, I just wondered if there's an approach I hadn't considered which would be more appropriate? 我知道我可以使用应用程序委托变量,单例或nsuserdefault设置,我只是想知道是否有一种我没有考虑过的方法更合适?
I know I could call the function within back buttons etc, but the call within viewWillAppear will overwrite this. 我知道我可以在后退按钮等中调用该函数,但是在viewWillAppear中的调用将覆盖此函数。
+ (void)transitionFromRight:(UIViewController*)view {
CATransition *navTransition = [CATransition animation];
navTransition.duration = 0.65;
navTransition.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[navTransition setType:kCATransitionReveal];
[navTransition setSubtype:kCATransitionFromRight];
[view.navigationController.navigationBar.layer
addAnimation:navTransition forKey:nil];
}
I'm assuming you're using a UINavigationController
. 我假设您正在使用
UINavigationController
。
None of the options you suggest are appropriate because they're all variants on the idea of global data access point, which you shouldn't need for something like this. 您建议的所有选项都不是合适的,因为它们都是全局数据访问点概念的变体,您不需要像这样的东西。
Here's a better way: 这是一个更好的方法:
Create a UINavigationControllerDelegate
for your UINavigationController.
创建
UINavigationControllerDelegate
为您UINavigationController.
You'll get to hear about new views being pushed/popped onto the nav stack via one of the delegate methods such as navigationController:willShowViewController:animated:
. 您将听到通过委托方法之一(例如
navigationController:willShowViewController:animated:
将新视图推送/弹出到导航堆栈中的信息。 In the appropriate delegate method you can set a property on your custom UIViewController so that it knows which animation to use in viewWillAppear etc. 在适当的委托方法中,您可以在自定义UIViewController上设置一个属性,以便它知道在viewWillAppear等中使用哪个动画。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.