iOS:在 rootViewController 动画不正确的方向?

标签 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"];

当设备处于纵向模式时,一切都很顺利。但是,当设备处于横向模式时,过渡动画的执行就像设备仍处于纵向模式一样。例如:不是从左边进来,而是从下面进来。两种观点的方向都是完全正确的。只有过渡很奇怪。

最佳答案

所以,我一直在研究您的代码(我对您的项目设置方式进行了最佳猜测重构),并且我能够通过以下代码获得预期的效果。我尝试设置层、 View 或子层等的框架和边界,但都没有用。 CATransform3D、CATransform3DRotates 等也没有解决问题。我也用谷歌搜索了整整一个小时。要么没有人遇到您的问题,要么没有人解决您的问题。无论如何,这个解决方案是可行的,除非一些 Core Animation 大师可以提供更好的解决方案,否则欢迎您使用:

- (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"];
}

关于iOS:在 rootViewController 动画不正确的方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9842949/

相关文章:

ios - 具有动态高度的 UITableView 行在 IOS 8 中工作,在 iOS 7 中不工作

c++ - 为什么 SFML Xcode 不使用 C++ 加载我的 .png 文件?

iphone - UI 事件 View Controller 以不同的语言显示?-iOS

ipad - Monotouch - 带有 iPad 应用程序的 UIImagePickerController

ios - 你如何在 Swift 中为 iOS 制作垂直文本 UILabel 和 UITextView?

ios - 恢复 View 状态而不对 segue 进行动画处理

swift - 在 Swift Core Data 中对存储的数据模型提取进行排序

xcode - 如果运行脚本阶段出现错误,如何中止构建

iphone - 用于 ipad 的 cocos2d 的动态菜单

ios - 从右到左语言的 UIScrollView 方向 RTL