我不知道我是否正确地这样做了。请帮我。我试图在屏幕上来回移动两张图像,使其看起来像是关闭和打开。
while (x>=1) {
var customFrame1 = Laser1.frame
if isImageLeftSide {
customFrame1.origin.x = customFrame1.origin.x + 25
}
else {
customFrame1.origin.x = customFrame1.origin.x - 25
}
var customFrame2 = Laser2.frame
if isImageLeftSide {
customFrame2.origin.x = customFrame2.origin.x + 25
}
else {
customFrame2.origin.x = customFrame2.origin.x - 25
}
x += 1
}
答案 0 :(得分:0)
使用此:
while (x >= 1) {
UIView.animateWithDuration(YOUR_ANIMATION_DURATION) {
if isImageLeftSide {
Laser1.frame.origin.x += 25
} else {
Laser1.frame.origin.x -= 25
}
}
UIView.animateWithDuration(YOUR_ANIMATION_DURATION) {
if isImageLeftSide {
Laser2.frame.origin.x += 25
} else {
Laser2.frame.origin.x -= 25
}
}
x += 1
}
注意:如果Laser1
和Laser2
是该类的属性,则必须在动画块中使用self.Laser1
和self.Laser2
。