【发布时间】:2015-10-16 12:23:49
【问题描述】:
我想显示触摸和移动对象的 x 坐标。
试试看:
import UIKit
class ViewController: UIViewController {
var location = CGPoint(x: 0, y: 0)
@IBOutlet weak var viewBox: UIView!
@IBOutlet weak var cntInViewBox: UILabel!
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.first! as UITouch
location = touch.locationInView(self.view)
viewBox.center = location
/*cntInViewBox.text=String(location.x)*/
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.first! as UITouch
location = touch.locationInView(self.view)
viewBox.center = location
/*cntInViewBox.text=String(location.x)*/
}
override func viewDidLoad() {
super.viewDidLoad()
viewBox.center = CGPoint(x:0, y: 0)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
没有线
cntIntViewBox.text=String(location.x)
效果很好。在屏幕上触摸,viewBox 跳跃,开始触摸,盒子在移动。
但如果我激活线条来显示坐标(例如,我的意思是任何动态文本),移动和跳跃就不再起作用了。
为什么会出现这个问题?
【问题讨论】:
标签: ios swift swift2 touchesbegan touchesmoved