[英]Is there any viewDidAppear method for UIView (not UIViewController)?
[英]Touches method in UIViewController and UIView
我正在使用iPad应用程序。 我的UIViewController
仅包含大小为500wx500h的自定义UIView
。
我在UIViewController
和自定义UIView
中都实现了touches方法,以便在我们触摸自定义UIView
周围时调用UIViewController
touches方法,并在内部触摸时调用自定义UIView
touches方法。
UIViewController touchesMoved:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];
NSLog(@"TEST"); // Added during edition
if (!CGRectContainsPoint(self.drawingView.frame, point)) {
NSLog(@"UIVIEWCONTROLLER");
}
}
自定义UIView触动Moved:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"CUSTOM VIEW");
}
当我用手指触摸自定义UIView
将记录CUSTOM VIEW
,直到我移开屏幕上的手指为止。 另一方面,当我触摸自定义UIView之外时,在touchesMoved方法中仅一次调用了UIVIEWCONTROLLER
。
我错过了什么地方吗?
编辑:我在我的UIViewController touchesMoved方法中添加了一个日志。 当我在自定义视图中触摸时,它将在所有触摸阶段记录“测试”。 但是当我在外面碰触时,我会得到相同的行为。
向视图添加ExclusiveTouch属性以禁用多点触摸
your view.exclusiveTouch=YES;
您的self.view有可能会拦截触摸并对其进行处理,因此它们不会传递给视图控制器。 您可以尝试执行以下两项操作之一(或同时执行两项操作),然后查看是否可行:
self.view.exclusiveTouch = NO;
self.view.userInteractionEnabled = NO;
我也会尝试调用[super touchesMoved: touches withEvent: event];
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.