表示モーダルのUIViewControllerでカバーするとUITouchイベントをキャンセル
-
22-09-2019 - |
質問
私は、ユーザーが自分の指を使って画面上にいくつかのものを移動し、それらをドロップすることがあるアプリケーションを書いています。これを行うには、私が移動させなければならない各ビューのtouchesBegan、touchesEnded ...機能を使用しています。
問題が時々ビューがビューで覆われていることである【のUIViewController presentModalViewController]関数を使用して表示されます。すぐにそれが起こるとして、それがアップ覆われていたので、私は、タッチイベントを受信停止を動かしたことのUIView。しかし、私が移動ビューの状態をリセットすることができますので、それは、イベントの受信を停止することを私に告げるイベントがない。
以下は、このことを示す例です。機能はメインウィンドウに表示されているのUIViewの一部です。これは、タッチイベントをリッスンし、私はいくつかの距離のために指をドラッグすると、それはすべてをカバーモーダルビューを提供します。実行ログでは、タッチイベントが受信されているものを印刷します。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touchesBegan");
touchStart=[[touches anyObject] locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint touchAt=[[touches anyObject] locationInView:self];
float xx=(touchAt.x-touchStart.x)*(touchAt.x-touchStart.x);
float yy=(touchAt.y-touchStart.y)*(touchAt.y-touchStart.y);
float rr=xx+yy;
NSLog(@"touchesMoved %f",rr);
if(rr > 100) {
NSLog(@"Show modal");
[viewController presentModalViewController:[UIViewController new] animated:NO];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touchesEnded");
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touchesCancelled");
}
私は、アプリケーションをテストして、表示するモーダルダイアログをトリガしたときにしかし、次のように実行ログで出力されます。
[セッションが2010年3月27日で開始 夜04時17分14秒-0700。] 2010-03-27 16:17:18.831 modelTouchCancel [2594:207] touchesBegan 2010-03-27 16:17:19.485 modelTouchCancel [2594:207] touchesMoved 2.000000 2010-03-27 16:17:19.504 modelTouchCancel [2594:207] touchesMoved 4.000000 2010-03-27 16:17:19.523 modelTouchCancel [2594:207] 16.000000 2010-03-27をtouchesMoved 16:17:19.538 modelTouchCancel [2594:207] 26.000000 2010-03-27をtouchesMoved 16:17:19.596 modelTouchCancel [2594:207] 68.000000 2010-03-27をtouchesMoved 16:17:19.624 modelTouchCancel [2594:207] 85.000000 2010-03-27をtouchesMoved 16:17:19.640 modelTouchCancel [2594:207] 125.000000 2010-03-27をtouchesMoved 16:17:19.641 modelTouchCancel [2594:207]ショーモーダル
そのタッチイベントがモーダルビューによって中断されているのUIViewの状態をリセットする方法上の任意の提案?
解決
モーダルビューが表示されているとき、あなたがコントロールしている場合、あなたはまた、彼らは移動ビューをリセットする必要があること、あなたのアプリの残りの部分を伝えるために同時に通知を送信することができますか?