Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want smooth transition or slide between pictures in an NSArray using UISwipeGesture

I have a UIImageView as one of my tabbarcontroller views, and I've added a UISwipeGestureRecognizer (right and left) to navigate through a series of photos in an NSArray.

However, when swiping it jumps from photo to photo with no smooth transition. I'm not after anything fancy, but even a slide animation would be okay, like as one photo slides in, the other is sliding out the other side. Is this possible with the UISwipeGestureRecgonizer and an NSArray?

like image 356
JamesBent Avatar asked Feb 20 '11 14:02

JamesBent


1 Answers

The standard solution is to use a UIScrollView with pagingEnabled = YES and multiple image views inside the scroll view. If you want to work with just one UIImageView, add a transition animation to the image view's layer when you recognize a swipe:

CATransition *animation = [CATransition animation];
animation.duration = 0.5;
animation.type = kCATransitionMoveIn;
animation.subtype = kCATransitionFromRight;
[myImageView.layer addAnimation:animation forKey:@"imageTransition"];
myImageView.image = newImage;
like image 186
Ole Begemann Avatar answered Jan 01 '23 08:01

Ole Begemann