开发者

How to make a UIView ignore touches without releasing it?

开发者 https://www.devze.com 2023-04-11 18:54 出处:网络
I have a transparent UIView on top of a UIScrollView. The UIView determines whether the scrollview is allowed to scroll or not by checking three touchesMoved events. After the events, I want the view

I have a transparent UIView on top of a UIScrollView. The UIView determines whether the scrollview is allowed to scroll or not by checking three touchesMoved events. After the events, I want the view to disable user interaction so scrolling will happen. The user shouldn't ev开发者_开发知识库en notice the delay.

However, having set the view's userInteractionEnabled to NO, it keeps claiming all touchesMoved events until it is released. This means that the user is forced to let go of the view before being able to scroll.

Using hitTest won't work until the view has been released as well. hitTest does not get called while moving.

I would send the touch events to the UIScrollView, but it happily ignores those due to it having its own hidden touch handling.

Any way to make the UIView stop claiming touch events without having to let go of it?


Make the UIView hidden. According to the docs:

A hidden view disappears visually from its window and does not receive input events

See the class reference for more: http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html


try cancelling the touches:

How to cancel a sequence of UITouch events?

p.s. if necessary I assume you are propagating the touches to next responder:

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    [[self nextResponder] touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent *)event {
    [super touchesMoved:touches withEvent:event];
    [[self nextResponder] touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];
    [[self nextResponder] touchesEnded:touches withEvent:event];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消