【发布时间】:2014-12-03 19:14:15
【问题描述】:
我正在尝试使用按钮停止视图中的动画正方形(循环上下)并读取位置(x,y) 这是运动的代码
override func viewDidLoad() {
super.viewDidLoad()
while buttonPress == false {
movement()
}
}
func movement() {
coloredSquare.backgroundColor = UIColor.blueColor()
coloredSquare.frame = CGRect(x:0, y:500, width:50, height:50)
self.view.addSubview(coloredSquare)
movementDown()
}
func movementDown() {
// lets set the duration to 1.0 seconds
// and in the animations block change the background color
// to red and the x-position of the frame
UIView.animateWithDuration(1.0, animations: {
self.coloredSquare.backgroundColor = UIColor.blueColor()
self.coloredSquare.frame = CGRect(x: 0, y: 500, width: 50, height: 50)
}, completion: { animationFinished in
self.movementUp()
})
}
func movementUp() {
UIView.animateWithDuration(1.0, animations: {
self.coloredSquare.backgroundColor = UIColor.redColor()
self.coloredSquare.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
}, completion: { animationFinished in
self.movementDown()
})
}
如果我尝试使用 WHILE 执行一个方法直到条件为假,Xcode 构建但模拟器停止在启动屏幕,如果我取消 while 条件,动画工作但没有任何停止... 谁能帮我? 谢谢
【问题讨论】:
标签: ios animation swift uiview