ios - 如何模仿相机应用程序 - 覆盖方向变化动画?

标签 ios objective-c swift animation uikit

我正在尝试创建一个与 Apple 的相机应用程序非常相似的 View Controller 。请注意,无论您如何转动手机,底栏如何始终粘在主页按钮上。各个元素旋转并四处移动以响应,但是 主视图保持原样。

我怎样才能重新创建它?

iOS Camera App Portrait
(来源:gcflearnfree.org)

iOS Camera App Lanscape http://content.gcflearnfree.org/topics/230/2013_camera_orient_lan.jpg

如果我为我的 View 启用方向,当整个 View 旋转时会有一个很大的分散注意力的动画。我需要把东西留在原地。

我尝试过在我的 View 中禁用方向更改,并手动为所有内容设置动画,但我需要呈现一个 UIAlertController,如果您旋转了手机,警报会上下颠倒或横向显示。

有没有办法允许方向改变,但让动画立即发生?然后我可以同时将元素移动到它们的新位置,它们看起来会保持不动。

如果不是,您将如何重新创建 iOS 相机应用的方向和布局行为?

最佳答案

这是从各种其他问题中拼凑而成的解决方案:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)

    let duration = coordinator.transitionDuration()
    UIView.animateWithDuration(duration, animations: {
        // things you want to animate go here
        // any animations we kick off before turning them off will continue
    })

    // prevent any animations until this completes
    UIView.setAnimationsEnabled(false)
    coordinator.animateAlongsideTransition({ context in

    }, completion: { context in
        // turn animations back on. 
        UIView.setAnimationsEnabled(true)
    })
}

关于ios - 如何模仿相机应用程序 - 覆盖方向变化动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37597972/

相关文章:

ios - UIViewController subview Controller 可访问性

具有透明背景的iOS 8重新排序控件

objective-c - 将键盘快捷键发送到 Mac OS X 窗口

iphone - 关于开发者证书的问题

ios - Sketch 和 iPhone 模拟器之间的颜色差异

ios - UICollectionView 高度不能使用内部 UIScrollView 动态递增

ios - iPad 屏幕底部的缝隙

ios - 检查设备上是否启用了 iTunes Match

swift - 如何重置 UICollectionVIewCell 的背景颜色

ios - 将更改部署到生产环境时,如何为 CKRecord 中的字段添加默认值?