flip transition flips view from top in landscape mode

拟墨画扇 提交于 2019-12-22 09:49:06

问题


I am using this code to for flip transition.

MyViewController *viewController = [[MyViewController alloc] init];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:YES];
[self.navigationController pushViewController:viewController animated:NO];
[UIView commitAnimations];
[viewController release];

But instead of fliping from right, its flipping from top. My application works only in landscape mode.

Please help.


回答1:


The animation constants have been defined with portrait mode in mind. If you define your application to be landscape mode only, you have to think about these animation constants with your head tilted 90 degrees.

Let's say your device's top is titled to the left, than you would set the animation with

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:YES];

and it would curl from the right. That's because the bottom of the device faces to the right in this case.

The bad thing is that UIViewAnimationTransitionFlipFromBottom is not defined. I guess you could rotate the coordinate system of the animation with 90 degrees, but I can't help you with that.




回答2:


I don't know what Apple was thinking when they developed this API. Here's the workaround I used:

// Assume this code is in a view controller subclass
- (UIViewAnimationOptions)viewAnimationOptionTransitionFlipFromRight
{
    switch (self.interfaceOrientation) {

        case UIInterfaceOrientationPortrait:
            return UIViewAnimationOptionTransitionFlipFromRight;

        case UIInterfaceOrientationLandscapeLeft:
            return UIViewAnimationOptionTransitionFlipFromBottom;

        case UIInterfaceOrientationLandscapeRight:
            return UIViewAnimationOptionTransitionFlipFromTop;

        case UIInterfaceOrientationPortraitUpsideDown:
            return UIViewAnimationOptionTransitionFlipFromLeft;
    }
}

You can adjust the code accordingly if you want to flip in a different direction. If you want to use the page curl transitions, however, I'm afraid you may be completely out of luck.



来源:https://stackoverflow.com/questions/5262908/flip-transition-flips-view-from-top-in-landscape-mode

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