我正在处理的项目的一部分需要我使用触摸移动对象。我目前正在运行Swift 3.1和Xcode 8.3.3。第7行给我的错误说:设置<UITouch>没有会员“位置”
'Set<UITouch>'
类型的值没有任何成员“location
”
可是我已经看过了的文档,这是一个成员。有一些解决方法吗?我只需要基于触摸和拖动来移动图像。
import UIKit
class ViewController: UIViewController {
var thumbstickLocation = CGPoint(x: 100, y: 100)
@IBOutlet weak var Thumbstick: UIButton!
override func touchesBegan(_ touches:Set<UITouch>, with event: UIEvent?) {
let lastTouch : UITouch! = touches.first! as UITouch
thumbstickLocation = touches.location(in: self.view)
Thumbstick.center = thumbstickLocation
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
let lastTouch : UITouch! = touches.first! as UITouch
thumbstickLocation = lastTouch.location(in: self.view)
Thumbstick.center = thumbstickLocation
}