![](/img/trans.png)
[英]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.