【问题标题】:Device rotation animation won't work in iOS 10设备旋转动画在 iOS 10 中不起作用
【发布时间】:2025-12-23 08:25:12
【问题描述】:

我遇到了如下问题,找了好几个地方,都没有找到解决办法,因为我在AppDelegate中的didFinishLaunchingWithOptions中添加了几行代码,来确定在哪个ViewController会启动开始并使用在关闭应用程序之前保存的数据加载数组,旋转设备时,在模拟器或我的 iPhone 中,旋转时不会生成动画。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    func preferredStatusBarStyle() -> UIStatusBarStyle {
        return UIStatusBarStyle.lightContent
    }

    UINavigationBar.appearance().barTintColor = UIColor(red: 252/255.0, green: 140.0/255.0, blue: 90.0/255.0, alpha: 1)
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white]
    UIToolbar.appearance().barTintColor = UIColor(red: 252/255.0, green: 140.0/255.0, blue: 90.0/255.0, alpha: 1)
    UIBarButtonItem.appearance().tintColor = UIColor.white

    self.window = UIWindow(frame: UIScreen.main.bounds)
    let storyboard = UIStoryboard (name: "Main", bundle: nil)

    ...
}

这里是 GIF:

【问题讨论】:

    标签: ios swift animation screen-rotation


    【解决方案1】:

    按设备方向自动旋转动画

    问题

    • iOS 11:正常工作
    • iOS 9、10:不工作

    解决方案

    如果您在AppDelegate 中有“主界面”和自定义窗口设置,请删除其中一项。

    我通过删除“目标 - 常规 - 主界面”解决了这个问题。 (将其设置为空白。)
    但是,通过设置主界面,我仍然不知道为什么会出现这个问题。

    【讨论】: