0

ユーザーが指を使って画面上で何かを動かしてドロップする必要があるアプリケーションを書いています。これを行うには、移動する必要がある各ビューの 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-03-27 16:17:14 -0700 で開始されました。 ] TouchMoved 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] TouchESMoved 16.000000 2010-03-27 16:17:19.538 ModelTouchCancel [2594:207] touchesMoved 26.000000 2010-03-27 16:17:19.596 modelTouchCancel[2594:207] touchesMoved 68.000000 2010-03-27 16:17:19.624 modelTouchCancel[2594:207] touchesMoved 85.07-2010: 17:19.640 modelTouchCancel[2594:207] touchesMoved 125.000000 2010-03-27 16:17:19.641 modelTouchCancel[2594:207] モーダル表示

モーダル ビューによってタッチ イベントが中断されたときに UIView の状態をリセットする方法について何か提案はありますか?

4

1 に答える 1

0

モーダル ビューがいつ表示されるかを制御している場合、同時に通知を送信して、移動したビューをリセットする必要があることをアプリの残りの部分に伝えることはできますか?

于 2010-03-28T00:18:32.757 に答える