我想为所有屏幕尺寸创建类似的动画。我的中心有 UIView
,我想向右移动,UIView
和屏幕之间的距离应为 10。
怎么做?
我的一个屏幕代码(iPhone 5s):
UIView.animate(withDuration: 1.0, delay: 0.0, options: [], animations: {
self.imageRevealed.center.x += 200
})
在这种情况下,UIView
和屏幕之间的距离 = 10。但对于其他屏幕,我应该使用新坐标编写新代码。如何编写通用代码?
最佳答案
我认为您需要 10px 的 ImageView 和 View 之间的尾随空间。
let trailingSpace: CGFloat = 10
UIView.animate(withDuration: 1.0, delay: 0.0, options: [], animations: {
let screenSize = UIScreen.main.bounds.size
let x = screenSize.width - self.imageRevealed.frame.size.width - trailingSpace
let y = self.imageRevealed.frame.origin.y
self.imageRevealed.frame = CGRect(x: x, y: y, width: self.imageRevealed.frame.size.width, height: self.imageRevealed.frame.size.height)
})
关于ios - Swift:移动 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51112354/