基本上...
我有一个UIScrollView子类,您也可以添加目标和选择器,如果在视图中检测到触摸事件,则会触发该子类。我使用滚动视图作为图库,滚动视图内的触摸用于淡出HUD组件(UItoolBar等):
@implementation TouchableScrollView
- (void)addTarget:(id)_target withAction:(SEL)_action
{
target = _target;
action = _action;
shouldRun = NO;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
shouldRun = YES;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
shouldRun = NO;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if(shouldRun)
{
shouldRun = NO;
[target performSelector:action];
}
}
@end
然后我又添加了另一个自定义UIView作为子视图,其中包含以下设置(我用过的两个):
self.userInteractionEnabled = YES;
self.exclusiveTouch = YES;
并使用以下内容触发动画:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
问题是即使自定义UIView检测到触摸并做出响应(通过翻转自身),UIScrollView选择器也会被触发,导致所有内容淡出。
请帮忙,我完全被卡住了?!
答案 0 :(得分:0)
最好在自定义ScrollView类
中使用它 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
if (!self.dragging) {
[self.nextResponder touchesEnded: touches withEvent:event];
}
[super touchesEnded: touches withEvent: event];
self.nextResponder
是scrollView子视图。所以其他事件然后拖动(滚动)将由您的主viewController处理。在主视图控制器中继承触摸事件方法。你可以检查特定视图或图像视图的触摸事件。