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

Byt*_*yte 7 xcode animation orientation ipad ios

上下文:我正在尝试执行从普通UIViewController.view到自定义的自定义动画UISplitViewController.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"];
Run Code Online (Sandbox Code Playgroud)

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

jms*_*617 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"];
}
Run Code Online (Sandbox Code Playgroud)