开发者

Changing Animation from sliding left-right to right-left for back button! navigation

开发者 https://www.devze.com 2023-02-01 11:33 出处:网络
-(IBAction) takeNextStep : (id) sender { SecondViewController *varSecondViewController =[[SecondViewController alloc] initWithNibName:@\"SecondViewController\" bundle:nil开发者_StackOverflow社区];
-(IBAction) takeNextStep : (id) sender
{   
     SecondViewController *varSecondViewController =[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil开发者_StackOverflow社区];
}

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!


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"];


You might use something like this...

(Requires < 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).

Give it a go. Enjoy.

0

精彩评论

暂无评论...
验证码 换一张
取 消