繁体   English   中英

如何处理UITableView或ScollView之类的触摸事件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM