将动画从左右滑动变为后退按钮!导航

时间:2010-12-29 19:18:58

标签: iphone xcode animation uinavigationcontroller back-button

-(IBAction) takeNextStep : (id) sender
{   
     SecondViewController *varSecondViewController =[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
}

如何将其从默认滑动从左向右(向前)向右向左(向后)滑动 因为我有一个自定义按钮,因此我设法编程我的自定义按钮返回到根,但它从右向左滑动,从而导致用户混淆

谢谢!

2 个答案:

答案 0 :(得分:4)

与Xen的答案类似,请下载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"];

答案 1 :(得分:2)

你可以使用这样的东西......

(需要< 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"];
}

这是一个自定义功能,可以将视图从右向左滑动(方向= 0),反之亦然(方向= 1)。

试一试。享受。