iOS版:在RootViewController的动画不正确的方向? [英] iOS: Animating Incorrect Orientation at rootViewController?

查看:160
本文介绍了iOS版:在RootViewController的动画不正确的方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:我想从正常执行自定义动画 UIViewController.view UISplitViewController.view 。动画应显示由左到右。

Context: I am trying to perform a custom animation from a normal UIViewController.view to a UISplitViewController.view. The animation should show from Left to Right.

我设置 self.window.rootViewController =的viewController ,其中的viewController 是一个正常的的UIViewController

I set self.window.rootViewController = viewController where viewController is a normal UIViewController.

一旦用户刷卡,下面被调用:

Once the user swipe, the following gets called:

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

当设备处于纵向模式,一切都进行得很完美。然而,当设备处于风景模式中,过渡动画执行如同设备仍处于纵向模式。例如:不是从左边来在,它从底部的用武之地。双方的观点的方向是完全正确的。只有转变是怪异。

When the device is in a portrait mode, everything went perfectly. However, when the device is in the landscape mode, the transition animation performs as if the device is still in the portrait mode. For example: Instead of coming in from the left, it comes in from the bottom. The orientation of both the views are completely correct. Only the transition is weird.

推荐答案

所以,我一直在你的code玩弄(我做了一个最好的猜测是如何你有你的项目设置重建)和我能得到具有以下code预期的效果。我试着设置的视图或子层等的框架和层次的界限,并没有任何的工作。 CATransform3D的,CATransform3DRotates等还没有做的伎俩。我也用Google搜索了坚实小时。要么没有人有你的问题,或者没有人解决您的问题。无论如何,这个解决方案有效,除非一些核心动画大师可以提供更好的解决方案,欢迎您这样的:

So, I've been playing around with your code (I did a best-guess reconstruction of how you have your project set up), and I was able to get the desired effect with the following code. I tried setting the frames and bounds of layers, of views, or sublayers, etc., and none of that worked. CATransform3D's, CATransform3DRotates, etc also weren't doing the trick. I also Googled for a solid hour. Either no one has had your issue, or no one has solved your issue. Regardless, this solution works, and unless some Core Animation guru can provide a better solution, you're welcome to this:

- (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的动画不正确的方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆