スワイプの方向に応じて、画像を左右またはvvでスワイプするジェスチャレコグナイザーがいくつかあります。しかし、私はアニメーションをよりスムーズにしたいと思っています。これはこれまでの私のコードです:
-(void)swipeNext:(id)sender{
//0 Get the currentview as referenced by pageControl
UIImageView *oldView = [views objectAtIndex:currentViewIndex];
//MOVE ON TO NEW VIEW
currentViewIndex ++;
NSLog(@"left swiped - currentViewIndex:%d", currentViewIndex);
UIImageView *newView = [views objectAtIndex:currentViewIndex];
//NSLog(@"views objectAtIndex = %@",[views objectAtIndex:[self.pageControl currentPage]]);
//1 Animate out the old view
newView.frame = oldView.frame;
newView.center = CGPointMake(oldView.center.x + CGRectGetWidth(oldView.frame), oldView.center.y);
[oldView.superview addSubview: newView];
[UIView animateWithDuration:1.0
delay: 0.0
options: UIViewAnimationOptionCurveEaseIn //UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
newView.center = oldView.center;
oldView.center = CGPointMake(oldView.center.x - CGRectGetWidth(oldView.frame), oldView.center.y);
}
completion:nil];
}
もう少し速くしたいのですが。エミュレートしようとしているアプリ、DunkinDonuts(Dunkin Donutsアプリが使用するビューコントローラーの種類)への参照として投稿しました。最初はUIPageControlを使用しているようですが、スワイプの方向を判断するのに問題がありました(UIPageControlを使用してUIImageViewを左から右にアニメーション化するにはどうすればよいですか?)、ジェスチャに切り替えました。ただし、アプリが表示されている場合は、スワイプの方が高速です。