I have implemented a pretty simple picture viewer that will allow the user to browse through a collection of images. They are loaded from the Internet, and displayed on the device through a UIImageView
object. Something like this:
UIImage *image = [[UIImage alloc] initWithData:imageData];
[img setImage:image];
imageData
is an instance of NSData
that I use to load the contents of the image from an URL, and img
is the UIImageView
instance.
It all works well, but the new image replaces the one being displayed before without any transitions, and I was wondering if there is an easy way to do a good animation transition to improve the user experience.
Any idea how to do this? Code samples would be very appreciated.
Nothing different from what's been explained but in code, these are the available transitions:
Code (Put this in a callback like touchesEnded):
There are several ways to do it and I agree with Ben View Transitions is a great example. If you are looking for simple full screen transitions I would just consider starting a new utility application and look at toggleView method in the RootViewController.m. Try switching out the UIViewAnimationTransitionFlipFromLeft and UIViewAnimationTransitionFlipFromRight to UIViewAnimationTransitionCurlUp and UIViewAnimationTransitionCurlDown for a really nice transition effect (this only works on the device).
here is what i have done: a fading. i put another UIImageView with the same UIImage and dimension called tmp. i replace the UIImage of the base UIImageView. Then i put the right image on the base (still covered by tmp).
Next step is - to set alpha of tmp to zero, - to stretch the base UIImageView to right ratio of the new UIImage based on the height of the base.
Here is the code:
The trick is you make two UIImageView instances. You swap them in between calls to UIView +beginAnimations and +commitAnimations.
I was just going through your post and had exactly the same requirement. The problem with all above solutions is, you will have to incorporate the logic of transition into your controller. In the sense the approach is not modular. Instead I wrote this subclass of UIImageView:
TransitionImageView.h file:
TransitionImageView.m file:
You can even override the
-setImage
method of UIImageView and call my-setImage:withTransitionAnimation:
method. If it is done like this make sure that you call[super setImage:]
instead of[self setImage:]
in the method-setImage:withTransitionAnimation:
so that it wont end up in infinite recursive call!-Raj