[英]How to handle touch event on UIButton added on cell of UITableView?
[英]how to handle touch event like UITableView or ScollView
我做了一个客户的控制,从继承UIView
,并增添了不少UIButton
在S UIView
。 当用户触摸并移动时,我会做一些动画:让按钮通过touchesMoved
函数移动:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
但buttonClick事件似乎具有更高的优先级。
我希望它可以像UITableView
一样,滚动的内容具有更高的优先级,然后单击按钮。
您需要研究UIPanGestureRecognizer 。
它使您能够取消发送到其他处理程序的事件。
更新了有关如何保护先前点的其他信息。
在动作回调中,您会收到有关初始触摸位置recognizer.state == UIGestureRecognizerStateBegan
通知。state recognizer.state == UIGestureRecognizerStateBegan
。 您可以将此点另存为实例变量。 您还会以不同的时间间隔收到callbackcognition.state recognizer.state == UIGestureRecognizerStateChanged
。 您也可以保存此信息。 然后,当您使用recognizer.state == UIGestureRecognizerStateEnded
获得回调时,您将重置所有实例变量。
- (void)handler:(UIPanGestureRecognizer *)recognizer
{
CGPoint location = [recognizer locationInView:self];
switch (recognizer.state)
{
case UIGestureRecognizerStateBegan:
self.initialLocation = location;
self.lastLocation = location;
break;
case UIGestureRecognizerStateChanged:
// Whatever work you need to do.
// location is the current point.
// self.lastLocation is the location from the previous call.
// self.initialLocation is the location when the touch began.
// NOTE: The last thing to do is set last location for the next time we're called.
self.lastLocation = location;
break;
}
}
希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.