我刚刚开始学习Swift,并且一直试图移动UIView以响应触摸。我收到一个exc_bad_instruction
错误。将UIView中心设置为cgpoint时的exc_bad_指令
var location = CGPoint(x: 0, y:0)
@IBOutlet weak var person: UIView!
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch : UITouch! = touches.first
location = touch.location(in: self.view)
person.center = location
}
哪一行抛出错误? –
@ Mr.UB第6行 –
'center'的类型是什么,'print(location)'的输出是什么? –