xcode 将动画从左右滑动更改为后退按钮的左右滑动!导航
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4557109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing Animation from sliding left-right to right-left for back button! navigation
提问by AlsonToh-SG
-(IBAction) takeNextStep : (id) sender
{
SecondViewController *varSecondViewController =[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
}
how do i change it from the default sliding from left to right (Forward) to right to left (backwards) as i have a custom button thus i managed to program my custom button to go back to the root , however it slides from right to left thus causing user confusion
我如何将它从默认的从左向右(向前)滑动到从右向左(向后)滑动,因为我有一个自定义按钮,因此我设法对我的自定义按钮进行编程以返回到根目录,但是它从右向滑动离开从而导致用户混淆
thanks!
谢谢!
回答by justinkoh
Similar to Xen's answer, download the sample code here.
// get the view that's currently showing
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view
UIView *theWindow = [currentView superview];
UIView *newView = aTwoViewController.view;
// remove the current view and replace with myView1
[currentView removeFromSuperview];
[theWindow addSubview:newView];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToView2"];
回答by Daniel G. Wilson
You might use something like this...
你可能会使用这样的东西......
(Requires < QuartzCore/QuartzCore.h >)
(需要 <QuartzCore/QuartzCore.h>)
- (void)switchTwoViews:(UIView *)view1 otherView:(UIView *)view2 direction:(int)directionRL{
view2.bounds = CGRectMake(0, 0, 480, 320);
visibleView = view2;
// remove the current view and replace with view1
[view1 removeFromSuperview];
[currentOptionsView addSubview:view2];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
if (directionRL == 0) {
[animation setSubtype:kCATransitionFromRight];
} else {
[animation setSubtype:kCATransitionFromLeft];
}
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[currentOptionsView layer] addAnimation:animation forKey:@"SwitchToView"];
}
That's a custom function that slides a view from right to left (direction = 0) or vice versa (direction = 1).
这是一个自定义函数,从右向左滑动视图(方向 = 0),反之亦然(方向 = 1)。
Give it a go. Enjoy.
搏一搏。享受。