Custom Segue push weird behavior

眉间皱痕 提交于 2019-12-24 00:14:06

问题


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;

}


来源:https://stackoverflow.com/questions/14920254/custom-segue-push-weird-behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!