iOS:在rootViewController上设置不正确的方向?

时间:2012-03-23 16:32:26

标签: ios xcode ipad animation orientation

上下文:我正在尝试从普通UIViewController.viewUISplitViewController.view执行自定义动画。动画应该从左到右显示。

我设置self.window.rootViewController = viewController viewController为正常UIViewController

用户滑动后,会调用以下内容:

UIView *theWindow = [viewController.view superview];

[viewController.view removeFromSuperview];
[theWindow addSubview:self.splitViewController.view];


CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];

当设备处于纵向模式时,一切都很顺利。但是,当设备处于横向模式时,过渡动画的效果就像设备仍处于纵向模式一样。例如:它不是从左边进入,而是从底部进入。两个视图的方向都是完全正确的。只有过渡是奇怪的。

1 个答案:

答案 0 :(得分:9)

所以,我一直在玩你的代码(我做了最好的重建你如何设置你的项目),并且我能够通过以下代码获得所需的效果。我尝试设置图层的层数和边界,视图或子图层等,但没有一个工作。 CATransform3D,CATransform3DRotates等也没有做到这一点。我也用Google搜索了一个小时。没有人遇到过您的问题,或者没有人解决您的问题。无论如何,这个解决方案是有效的,除非一些核心动画大师可以提供更好的解决方案,欢迎你这样做:

- (void)swipeGesture:(UISwipeGestureRecognizer *)sender {

UIView *theWindow = [self.viewController.view superview];

UIInterfaceOrientation interfaceOrientation = self.viewController.interfaceOrientation;
NSString *subtypeDirection;
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
    subtypeDirection = kCATransitionFromTop;
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
    subtypeDirection = kCATransitionFromBottom;
}
else {
    subtypeDirection = kCATransitionFromLeft;
}

[self.viewController.view removeFromSuperview];
[theWindow addSubview:self.splitViewController.view];

CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:subtypeDirection];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
}