我正在處理的項目的一部分需要我使用觸摸移動對象。我目前正在運行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
}