的頂視圖時touchesEnded不叫我有包含文本行只有一個簡單的tableview(所述細胞是標準的UITableViewCell和我簡單地修改其.textLabel屬性)。刷上的tableview
我已經編程增加了一個的UIView到tableview中,並使它看起來像一個紅色方塊在桌子上。我也爲這個方形視圖分配了一個UIPanGestureRecognizer。這個想法是能夠在整個tableview中拖動方形視圖。
我可以看到的(overrided)功能的touchesBegan和touchesCancelled是正常的調用。 touchesEnded只有在我沒有滑動方塊視圖時纔會調用,這只是點擊,不拖動。
通過閱讀類似的帖子我瞭解,問題是,UIGestureRecognizer被識別刷卡,這將覆蓋touchesEnded,但我不知道如何處理這個問題。
非常感謝您的幫助!
更新以包含代碼。
從TableViewController。令牌是我想要拖動的自定義視圖(前面提到的「方形視圖」)。
override func viewDidAppear(animated: Bool) {
let token = Token(frame: CGRect(x: 10, y: 10, width: 20, height: 20), color: UIColor.redColor())
self.view.addSubview(token)
self.view.bringSubviewToFront(token)
}
令牌,我的自定義視圖:
class Token: UIView {
var lastLocation:CGPoint = CGPoint(x: 10, y: 10)
init(frame: CGRect, color: UIColor) {
super.init(frame: frame)
self.backgroundColor = color
let panRecognizer = UIPanGestureRecognizer(target:self, action:"detectPan:")
self.gestureRecognizers = [panRecognizer]
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func detectPan(recognizer:UIPanGestureRecognizer) {
let translation = recognizer.translationInView(self.superview!)
self.center = CGPointMake(lastLocation.x + translation.x, lastLocation.y + translation.y)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
print("began")
// Promote the touched view
self.superview?.bringSubviewToFront(self)
// Remember original location
lastLocation = self.center
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
print("touchesEnded")
}
}
能否請你展示一些代碼,你是如何在UITableView'的'頂部加入這個'UIView'。 – Abhinav
你走了,先生!我希望是否足夠。否則,請告訴我!非常感謝! –
嘗試使用我提到的財產,即使使用手勢識別器,您也應該可以接觸到。 – Abhinav