我只是想用UIImageView做一个小转盘,当我添加第二张图片时会发生一些奇怪的事情。从只有1个图像开始我只想将它发送到左侧,所以我只是做了下面的代码,它完全正常,我的意思是,图像按预期向左移动。
let frame = self.mainImage.frame
var newFrame = frame
UIView.animateWithDuration(0.9, animations: { () -> Void in
self.mainImage.frame.origin.x = 0 - frame.size.width
}, completion: { (done) -> Void in
if done {
self.mainImage.frame = frame
}
}
)
然而,当我添加第二张图像时,两张图像都来自右侧。也许这很容易,但我看不出发生了什么。
let frame = self.mainImage.frame
var newFrame = frame
newFrame.origin.x = self.view.frame.size.width + 50
let newImageView = UIImageView(frame: newFrame)
newImageView.image = UIImage(named: "C2")
newImageView.contentMode = .ScaleAspectFit
self.view.addSubview(newImageView)
UIView.animateWithDuration(0.9, animations: { () -> Void in
self.mainImage.frame.origin.x = 0 - frame.size.width
newImageView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height)
}, completion: { (done) -> Void in
if done {
self.mainImage.frame = frame
newImageView.removeFromSuperview()
}
}
)