iOS:旋转iPad,什么阶段改变视图?

发布于 2025-01-04 19:56:18 字数 86 浏览 6 评论 0原文

我的应用程序对于每个方向都有非常不同的 UI 结构。

我应该在 iPad 旋转生命周期的哪个阶段删除然后添加方向的 UI 以确保最平滑的过渡?

My app has very different UI structures for each orientation.

At what stage in the rotation lifecycle of an iPad should I remove, then add the orientation's UI to ensure the smoothest transition?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜泪 2025-01-11 19:56:18

处理自动旋转时,有 4 个主要方法需要关心:

shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation                                   duration:(NSTimeInterval)duration

willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                            duration:(NSTimeInterval)duration

didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

现在,我处理旋转的方式是,例如:

  1. 调整 willAnimateRotationToInterfaceOrientation 中的所有帧;

  2. willRotateToInterfaceOrientation中添加/删除子视图(如果需要);

  3. didRotateFromInterfaceOrientation中恢复子视图(如果需要)。

更一般地说,我修改了 willAnimateRotationToInterfaceOrientation; 中所有可动画化的属性。而我在 willRotateToInterfaceOrientation/didRotateFromInterfaceOrientation 中进行了所有不可动画的修改。

这就是 UIViewController 参考 提到了 willRotate/didRotate

要暂时关闭不需要的功能或在方向更改期间可能导致问题的功能,您可以重写 willRotateToInterfaceOrientation:duration: 方法并在其中执行所需的操作。然后,您可以重写 didRotateFromInterfaceOrientation: 方法,并在方向更改完成后使用它重新启用这些功能。

When handling autorotation, you have 4 main methods to care about:

shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation                                   duration:(NSTimeInterval)duration

willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                            duration:(NSTimeInterval)duration

didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

Now, the way I handle the rotation is, e.g.:

  1. adjust all the frames in willAnimateRotationToInterfaceOrientation;

  2. add/remove subviews (if needed) in willRotateToInterfaceOrientation;

  3. restore subviews (if needed) in didRotateFromInterfaceOrientation.

More in general, I modify all properties that are animatable in willAnimateRotationToInterfaceOrientation; while I do all modifications that are not animatable in willRotateToInterfaceOrientation/didRotateFromInterfaceOrientation.

This is what the UIViewController reference says about willRotate/didRotate:

To temporarily turn off features that are not needed or might otherwise cause problems during the orientation change, you can override the willRotateToInterfaceOrientation:duration: method and perform the needed actions there. You can then override the didRotateFromInterfaceOrientation: method and use it to reenable those features once the orientation change is complete.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文