动画过渡在横向方向上无法正常工作
我的应用程序仅支持横向右方向。
我正在尝试转换到视图控制器的视图,但是当它执行过渡动画(例如卷曲)时,视图旋转 90 度(因此,模拟器仍处于横向右方向,但视图显示为旋转) 90 度)。过渡完成后,它会旋转到正确的方向。我的代码如下。
- (IBAction)buttonTouched
{
MyViewController *aViewController = [[MyViewController alloc] initWithNibName:NSStringFromClass([MyViewController class]) bundle:nil];
[UIView transitionFromView:self.view
toView:aViewController.view
duration:2
options:UIViewAnimationOptionTransitionCurlUp
completion:NULL];
}
视图似乎没有收到“方向已更改”通知,因此它以纵向显示,然后在动画完成后更改为横向。我已经在 IB 中将其设置为横向布局。
编辑:我还尝试将视图控制器添加到自身的 IB 文件并转换到该视图(认为初始化和转换之间可能太接近),但发生了同样的事情。
My app only supports the landscape right orientation.
I'm trying to transition into a view controller's view, but when it performs the transition animation (such as curl up), the view is rotated 90 degrees (so, the simulator is still in landscape-right orientation, but the view appears rotated by 90 degrees). When the transition finishes it rotates to the correct orientation. My code is below.
- (IBAction)buttonTouched
{
MyViewController *aViewController = [[MyViewController alloc] initWithNibName:NSStringFromClass([MyViewController class]) bundle:nil];
[UIView transitionFromView:self.view
toView:aViewController.view
duration:2
options:UIViewAnimationOptionTransitionCurlUp
completion:NULL];
}
It appears as though the view doesn't get the "orientation changed" notification, so it presents it in portrait, and then changes to landscape after the animation finishes. I have set it up in IB so that it is all laid out in landscape.
EDIT: I also tried adding a View Controller to self's IB file and transitioning to that view (thinking maybe it was too close between the initialization and the transition) but the same thing happened.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,主要原因是 self.view (当前“知道”您处于横向状态)正在被一个没有该信息的新视图替换。所以一种想法是将 aViewController.view 作为 self.view 的子视图(假设 aViewController 是不透明的)。啊,你说,但是我失去了transitionFromView 的漂亮动画。好吧,尝试一下这个好处:
如果由于某种原因这对你不起作用,另一种方法是“教导”aViewController.view它实际上是一个横向视图:
还有一点是你的aViewController正在泄漏,所以你应该它是父视图控制器的保留属性。
Well, the main reason is that self.view (which currently "knows" that you're in landscape) is being replaced with a new view which doesn't have that information. So one thought is to just put aViewController.view as a subView of self.view (assuming that aViewController is opaque). Ah, you say, but then I lose the nice animation of transitionFromView. Well, try this niceness:
If for some reason that doesn't work for you, the alternative is to "teach" aViewController.view that it's really a landscape view:
One minor additional point is that your aViewController is leaking, so you should make it a retained property of the parent viewController.