【发布时间】:2015-09-28 01:32:26
【问题描述】:
我通过在 touchesBegan() 时在手指的位置创建 UIView 在屏幕上创建了一个圆圈:
在 ViewController 中:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let pos = touch.locationInView(view)
let radius: CGFloat = touch.majorRadius * 2
let circleView = CircleView(frame: CGRectMake(pos.x - radius / 2, pos.y - radius / 2, radius, radius))
view.addSubview(circleView)
}
}
在 CircleView 中:
override init(frame: CGRect) {
super.init(frame: frame)
let recognizer = UIPanGestureRecognizer(target: self, action: Selector("handlePan:"))
recognizer.delegate = self
self.addGestureRecognizer(recognizer)
}
这会创建圆圈,但当我移动手指时不会立即移动它。相反,我必须在 handlePan() 启动之前拿起我的手指并将其放回圆圈上。
考虑到可能有多个手指在屏幕上触摸和移动,有没有办法在不抬起生成其父视图的手指的情况下开始跟踪平移手势?
【问题讨论】:
标签: ios iphone swift uiview uigesturerecognizer