我做了一个自定义控件,继承自UIView
,并在UIView
上添加了很多UIButton
。当用户触摸和移动时,我会做一些动画:让按钮通过函数touchesMoved
移动
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
但buttonClick事件似乎具有更高的优先级。
我想它可以像UITableView
一样,滚动的东西比按钮点击有更高的优先级。
发布于 2012-05-27 21:22:15
你需要调查一下UIPanGestureRecognizer。
它允许您取消发送到其他处理程序的事件。
更新了有关如何保护以前的点的其他信息。
在操作回调中,您将得到初始触摸位置recognizer.state == UIGestureRecognizerStateBegan
的通知。您可以将该点另存为实例变量。您还可以在不同的时间间隔内获得回调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;
}
}
希望这能有所帮助。
https://stackoverflow.com/questions/10774129
复制相似问题