我刚开始 iOS 开发,正在学习 Swift 和 Xcode。我在 View Controller 中有一个 UIImageView 对象,并且想在它在两个图像之间切换时在屏幕上移动这个 UIImageView 。这是代码:
@IBOutlet weak var anImageView: UIImageView!
@IBAction func beginAnimation(sender: AnyObject) {
let imgListArray:[AnyObject] = [UIImage(named: "img1.png")!, UIImage(named: "img2.png")!]
anImageView.animationImages = imgListArray
anImageView.animationDuration = 0.5
anImageView.image = UIImage(named: "img1.png")
anImageView.startAnimating()
UIView.animateWithDuration(4.0, animations: {
self.anImageView.center = CGPoint(x: 600, y: 600)
}, completion: {finished in
self.anImageView.center = CGPoint(x:80,y:80)})
}
问题出在坐标上。 UIImageView 从屏幕外开始并且不在 (80,80) 处结束。切换很好。
我想我必须将坐标转换到 superview(?) 空间,但我尝试这样做并没有成功。例如,我尝试了 convertPoint 函数,但没有成功。
非常感谢任何指导!
谢谢。
最佳答案
您还没有明确指定您想要做什么,所以让我们专注于这段代码做什么:
UIView.animateWithDuration(4.0, animations: {
self.anImageView.center = CGPoint(x: 600, y: 600)
}, completion: {finished in
self.anImageView.center = CGPoint(x:80,y:80)
})
该代码表示:
无论现在在哪里,都开始将 ImageView 从该点移动到 (600,600)(除非您使用的是 iPad,否则它将在屏幕外)。
当它到达那里时,让它从 (600,600)跳到 (80,80)。
这就是你所说的。所以,如果这不是您想要的,请不要那样说!
关于ios - UIImageView 带有持续时间的动画,以及动画图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30739360/