我正在尝试创建一个与 Apple 的相机应用程序非常相似的 View Controller 。请注意,无论您如何转动手机,底栏如何始终粘在主页按钮上。各个元素旋转并四处移动以响应,但是 主视图保持原样。
我怎样才能重新创建它?
(来源: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/