0

我做了一个客户控件,继承自UIViewUIButtonUIView. 当用户触摸和移动时,我会做一些动画:让按钮按功能移动touchesMoved

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

但是 buttonClick 事件似乎具有更高的优先级。

我想它可以喜欢UITableView,滚动的东西比按钮点击有更高的优先级。

4

1 回答 1

1

您需要查看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;
    }
}

希望有帮助。

于 2012-05-27T13:22:14.543 回答