我刚刚开始学习 Swift,并且一直在尝试移动 UIView 以响应触摸。我收到 exc_bad_instruction
错误。
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
}
最佳答案
exc_bad_instruction
通常是空指针的提示。确保 Person
不为零。
另外,请确保您的属性名称以小写字母开头 - 在本例中为 person
。当使用 Person
时,您将面临调用 Type 而不是 Propery 的风险。
如果您需要进一步的帮助,请编辑您的帖子并添加项目的更多代码示例 - 特别是类 Person
和您使用它的整个 UIViewController
。
关于swift - 将 UIView 中心设置为 cgpoint 时的 exc_bad_instruction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39802909/