【发布时间】:2018-02-21 23:04:06
【问题描述】:
当我旋转我的设备时,屏幕中间的红色方块会移动以保持在屏幕中心,而不管旋转如何。但是,在旋转设备时,the square does not immediately reposition itself, instead the previous location of the square can be seen until the rotation animation is fully complete. 是否有一种方法可以让正方形在动画播放时立即重新定位,以便在旋转动画期间看不到它的旧位置?
import UIKit
class ViewController: UIViewController {
var square = UIView()
override func viewDidLoad() {
super.viewDidLoad()
square.isHidden = true
square = UIView(frame: CGRect(x: self.view.frame.width / 2 - 50, y: self.view.frame.height / 2 - 50, width: 100, height: 100))
square.backgroundColor = UIColor.red
self.view.addSubview(square)
square.isHidden = false
}
override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {
square.isHidden = true
square = UIView(frame: CGRect(x: self.view.frame.width / 2 - 50, y: self.view.frame.height / 2 - 50, width: 100, height: 100))
square.backgroundColor = UIColor.red
self.view.addSubview(square)
square.isHidden = false
}
}
【问题讨论】:
标签: ios swift uiviewcontroller uikit