Custom Segue push weird behavior

2019-07-19 14:32发布

问题:

I am trying a simple project (storyboard) where the user swipes from right to left to get to the next view and so on and to go back the user swipes from left to right. I want to achieve the transition to follow the swipe (L-->R or R-->L).

I have found this:

-(void)perform {

    UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
    UIViewController *destinationController = (UIViewController*)[self destinationViewController];

    CATransition* transition = [CATransition animation];
    transition.duration = .25;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
    transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom



    [sourceViewController.navigationController.view.layer addAnimation:transition
                                                                forKey:kCATransition];

    [sourceViewController.navigationController pushViewController:destinationController animated:NO];

}

but this doesn't seem to be doing what is supposed to do.

EXPLAIN:

when i m in landscape (my project only works in landscape) and home button is on the left, the animation comes from the TOP!!! When I m in landscape and home button is on the right the animation comes from the BOTTOM!!!

Although I have specified it to be from the left. The other thing is that it changes direction when i use diferent landscapes (homebutton on the left or right).

Any ideas why is this happening???

回答1:

Are your views in a nav controller? Have you tried simply using the segue with "push" style?

In your swipe gesture recognizer, just call:

[self performSegueWithIdentifier:@"NextScreenIdentifier" sender:sender];

and you should get the correct behavior (left->right / right->left transition).



回答2:

ok this is how I did it, although VERY un-orthodox.

Im checking the orientation of the iPad and then instead of going left or right im actually going top/ bottom... ok this is how I did it, although VERY un-orthodox.

Im checking the orientation of the iPad and then instead of going left or right im actually going top/ bottom...

if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
{
      //Landscape Left

//.......
       transition.subtype = kCATransitionFromTop;

}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
{
      //Landscape Right

//......
       transition.subtype = kCATransitionFromBottom;

}