覆盖设备旋转时 UIViewController 的默认动画
我想在设备旋转时提供自定义动画,完全覆盖默认动画。实现这一目标的最佳方法是什么?
顺便说一句,我计划的动画类型是:
a)当设备进入横向时,有一个新的视图从顶部滑动,就像它正在下降一样。
b) 当设备返回纵向时,该视图应向下滑动并消失。
I want to provide a custom animation when the device rotates, completely overriding the default one. What's the best way to achieve this?
BTW, the kind of animation I'm planning is:
a) When the device goes into landscape, have a new view slide from the top as if it was falling.
b) When the device goes back to portrait, that view should slide down and dissappear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最佳是主观的,取决于您的整个应用程序。
处理轮换事件的一种相当直接的方法是告诉系统不要这样做并自己处理它们。对于您想要的效果,即当设备旋转到侧面时,基本上相当于从侧面滑动(预旋转)视图,这似乎是合适的。
这是如何实现这种效果的一个非常基本的示例。
我在这里所做的是在
.xib
中添加一个横向的UIView
并将其连接到名为sideways< 的
IBOutlet
/代码>。在 viewDidLoad 中,我将其添加为子视图,预旋转它,并将其移出屏幕。我还将自己添加为设备旋转通知的观察者(请记住稍后将自己删除以接收该通知)。在shouldAutoRo..
中,我指出该 VC 仅处理纵向。当设备旋转时,
NSNotificationCenter
调用orientationChange:
。此时,如果设备向左旋转,我的侧视图将从右侧滑入(看起来像是向下滑动)。显然,对于两种横向方向,代码都会更复杂。此外,您可能必须调整动画时间,以使第二个视图感觉像是“下落”
Best is subjective and dependent upon your application as a whole.
One fairly straight-forward way of handling the rotation events is telling the system not to and handling them yourself. For your desired effect of what essentially amounts to sliding a (pre-rotated) view in from the side when the device is rotated to the side, this would seem appropriate.
Here is a very basic sample of how to achieve such an effect.
What I have done here is added a
UIView
with a landscape orientation in the.xib
and connected it to anIBOutlet
namedsideways
. InviewDidLoad
I add it as a subview, pre-rotate it, and move it offscreen. I also add self as an observer for the device rotation notifications (Remember to remove yourself later for that notification). And inshouldAutoRo..
I indicate that this VC only handles portrait.When the device rotates
NSNotificationCenter
callsorientationChange:
. At that point if the device is rotated to the left, mysideways
view will slide in from the right (which seems like it's sliding down).Obviously for both landscape orientations the code would be more complex. Also you would likely have to mess around with the animation timing to make it feel as if the second view is "falling"