私は自分のアプリケーションでモーダルコントロールを表示します。私は、ユーザーがジェスチャーでビューを「軽く叩く」ことができるようにしたいと思います。これはUIGestureRecognizer
にフックアップされアニメーションが正常に動作しない
- (void)handlePan:(UIPanGestureRecognizer *)recognizer {
CGFloat elasticThreshold = 100;
CGFloat dismissThreshold = 200;
CGPoint translation = [recognizer translationInView:self.view];
CGFloat newY = 0;
CGFloat translationFactor = 0.5;
if (recognizer.state == UIGestureRecognizerStateEnded) {
if (translation.y < dismissThreshold) {
newY = 0;
}
} else {
if (translation.y > elasticThreshold) {
CGFloat frictionLength = translation.y - elasticThreshold;
CGFloat frictionTranslation = 30 * atan(frictionLength/120) + frictionLength/10;
newY = frictionTranslation + (elasticThreshold * translationFactor);
} else {
newY = translation.y*translationFactor;
}
}
if (translation.y > dismissThreshold) {
[UIView animateKeyframesWithDuration:0.5 delay:0.0 options:0 animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.5 animations:^{
self.overlay.effect = nil;
self.collectionView.transform = CGAffineTransformMakeTranslation(0, self.view.frame.size.height);
}];
[UIView addKeyframeWithRelativeStartTime:0.1 relativeDuration:0.1 animations:^{
self.pageControl.frame = CGRectMake((self.view.frame.size.width-200)/2, self.view.frame.size.height, 200, 20);
}];
} completion:^(BOOL finished) {
if (finished) {
[self dismissViewControllerAnimated:YES completion:nil];
}
}];
} else {
self.collectionView.transform = CGAffineTransformMakeTranslation(0, newY);
self.pageControl.transform = CGAffineTransformMakeTranslation(0, (newY+self.collectionView.frame.size.height)-20);
}
}
:
self.pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
self.pan.delegate = self;
self.pan.maximumNumberOfTouches = 1;
[self.view addGestureRecognizer:self.pan];
しかし、何が起こることは完了ブロックがすぐに実行されるということです私はそのために以下のコードを書きました。したがって、ビューが下に移動して(dismissViewControllerAnimated
のため)、同時にoverlay.effect
が表示されなくなります。しかし、私が望むのは、私のアニメーションが起こることです。そして、View Controllerがそれを黙って却下することです。
何が問題なのですか?
残りのジェスチャー処理では何が起こっていますか?ジェスチャー状態が変更されたときにビューを移動していますか?パンが終わったときに何かをするだけで奇妙に思えます。 – jrturton
パンが終了したら、それを0に戻しています。それ以外の場合は、ビューを下に移動しています。 – user4992124
しかし、そのコードはあなたの質問にありません – jrturton