UIImageView Fade In/Out with NSArray - iphone

I have an NSArray of images that I want to fade in/out between each other (much like how Flickr handles their home screen).
The problem I'm having is figuring out how to utilize the [UIView beginAnimations]; with the NSArray... any idea?
My code is below.
Thanks in advance!
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"show_robmachado.jpg"],
[UIImage imageNamed:#"show_losness.jpg"],
[UIImage imageNamed:#"show_blanchard.jpg"],
[UIImage imageNamed:#"show_tonino.jpg"],
nil];
homeAnimation.animationImages = myImages;
homeAnimation.animationRepeatCount = 0; // 0 = loops forever
homeAnimation.animationDuration = 7.0;
[homeAnimation startAnimating];

The array method is really for simple frame-based animations, not for transitions.
Instead I would have two UIImageViews at the same position, and set up a timer that would work through the array, using UIView animations to animate one image view fading to an alpha of 0 and the other to an alpha of 1. Then you'd get a kind of fading switch you are going for.
The .image property on a UIImageView might also be animatable, try in a timed loop changing .image on an image view in a UIView based animation block and see if you get a cross-fade.

Related

caricature - Image animation in iOS

How to Implement this kind of animation in iOS objective c.
Currently I have implemented "CABasicAnimation" for this but still not able to achieve this very smoothly .
any suggestion ??
Thank you
You'll need to use Core Image with a combination of different distortion filters.
You can then animate the intensity of the filters over time.
I don't think that with CABasic animation you can obtain that. Probably is a little "movie" made by combination of CIFilterd images (check CIFilter class in the doc). Another way around (but I'm writing as I'm thinking) is mask the image somehow with a CAShapeLayer and use CAAnimation on it.
As Leena pointed out this is a simple loop of images.
Create your frames outside Xcode and then animate them this way:
NSArray *frames = [NSArray arrayWithObjects:[UIImage imageNamed:#"firstFrame.png"],
[UIImage imageNamed:#"secondFrame.png"],
// add other frames
, nil];
UIImageView *animatedImage = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
animatedImage.animationImages = frames;
animatedImage.animationDuration = 3.0f; // seconds
animatedImage.animationRepeatCount = 0; // 0 = loops forever
[animatedImage startAnimating];
[self.view addSubview:animatedImage];
[animatedImage release];

How to create a map (UIImage) with buttons on it that animate?

i have a map (just an image) and i want that a user can click on some places on the map. I think i can do that with adding buttons as subviews. But i also want to animate them. So for example want to have a ring form around the link position. And this ring should animate like pulsing or so. How can i do that the best way?
greets Max
Not sure why nobody has tried to answer this but it's not too difficult.
First, create a UIImageView and configure it to animate your desired effect. The UIImageView documentation is very clear on what to do. Something like:
NSArray *imageArray = [NSArray arrayWithObjects:
[UIImage imageNamed:#"frame1.png],
[UIImage imageNamed:#"frame2.png],
...,nil];
UIImageView *animatedImageView = [[UIImageView alloc] initWithFrame:myFrame];
animatedImageView.animatedImages = imageArray;
animatedImageView.userInteractionEnabled = YES;
[self.view addSubView:animatedImageView];
[animatedImageView startAnimating];
You then have to add the code to respond to touch events on the imageView.
Alternatively, you can create a UIButton subclass that displayed an animated UIImageView per above and then use the standard addTarget:action to respond to user actions.

how to make growing flower animation between two views

i have a UIButton in a viewcontroller's view, i wrote action method form that i am going to another view controller's view. Now i am trying to implement animation between to views.i tried with many types one of the type animation is shown below
[UIView beginAnimations:#"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[self.view addSubview:anotherView];
[UIView commitAnimations];
This animation is working well but i am trying to implement some "growing flower animation"(name may be different) means the other view pop up from the button co-ordinatesand occupy entire screen.my custombutton` co-ordinates are (500,500,20,20).can any one suggest me for implementing this animation.
Thank you.
This can be achieved by various methods.
You can use:-
1 )
Core animations
UIImage class's animations
Cocos 2D
UIAnimation Classes (by simple changing the frames)
..and many more
It actually depends on your requirements, and your comfortable level with these classes/technologies.
If you just want to display growing flower, then the simpler (but not the optimized, and best) solution is to create different images,and put them in array, and then animate it
A similar example is available at: -
Animating images
If you have step by step images of growing flower images, then you can simply implement this. Write a function to implement simple implementation,
NSMutableArray * images;
//allocates the images array.
images = [[NSMutableArray alloc] init];
//loops till the 18images are added into array.
for (int index = 1; index < 19; index++) {
//get the image name.
NSString * imageName = [NSString stringWithFormat:#"Animation%d",index];
//get the path for the image in resourse file.
NSString * path = [[NSBundle mainBundle] pathForResource:imageName ofType:#"png"];
//allocate and own the image object for the particular image.
UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
//adds it to array.
[images addObject:image];
//release after adding.
[image release];
//remove the useless pointer.
image = nil;
}
//give the pointer to the array holding the images.
imageView.animationImages = images;
//after using it, release it.
[images release];
//remove the useless pointer
images = nil;
//set animation duration
imageView.animationDuration = 3.00;
//start animate
[imageView startAnimating];
After when you want to stop the animation you can simply call
[imageView stopAnimation];
You have another choice of
imageView.repeatCount = 1;
imageView is an instance of uiimageView, allocated one.

3D Rotation of Object

I am trying to rotate my object like shakes dice.
please suggest simplest way to implement it in my iphone application.
Any kind of sample code or documentation.
http://www.amazon.com/OpenGL-SuperBible-Comprehensive-Tutorial-Reference/dp/0321498828
If you want to do this without using OpenGL you can use a UIImageView and the set a series of animation images. By creating a series of images you can create a "rolling dice" effect. Here is an example of how to do this:
// create a UIImageView
UIImageView *rollDiceImageMainTemp = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"rollDiceAnimationImage1.png"]];
// position and size the UIImageView
rollDiceImageMainTemp.frame = CGRectMake(0, 0, 100, 100);
// create an array of images that will represent your animation (in this case the array contains 2 images but you will want more)
NSArray *savingHighScoreAnimationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"rollDiceAnimationImage1.png"],
[UIImage imageNamed:#"rollDiceAnimationImage2.png"],
nil];
// set the new UIImageView to a property in your view controller
self.viewController.rollDiceImage = rollDiceImageMainTemp;
// release the UIImageView that you created with alloc and init to avoid memory leak
[rollDiceImageMainTemp release];
// set the animation images and duration, and repeat count on your UIImageView
[self.viewController.rollDiceImageMain setAnimationImages:savingHighScoreAnimationImages];
[self.viewController.rollDiceImageMain setAnimationDuration:2.0];
[self.viewController.rollDiceImageMain.animationRepeatCount:3];
// start the animation
[self.viewController.rollDiceImageMain startAnimating];
// show the new UIImageView
[self.viewController.view addSubview:self.rollDiceImageMain];
You can modify the creation and setup including the size, position, number of images, the duration, repeat count, etc as needed. I've used this feature of UIImageView to create simple animation effects and it works great!
Please let me know if you try this and if it works for your needs. Also, post any follow up questions.
Bart
nice your example, but do you think it's possible to rotate / control the rotation with touch gesture ?

how to display an image and hide it in the animation function?

I want the image to be displayed and then hide and so on. I have tried nil and blank with out success. How can I accomplish this?
-(void) animationGlaw {
glawBall.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"1.png"],
[UIImage imageNamed:#""], nil];
glawBall.animationDuration = 0.50;
glawBall.animationRepeatCount = 0;
[glawBall startAnimating];
}
if you only want one image then none, you could try animating the opacity, and diong the animation very fast. If a fade out is acceptable then this would work even better. here is an example of animating the opacity.
you could also use the delegate to get notification when your animation ends and remove the image altogether, see here for an example of using the animationDidStop:finished: callback method.
Try using just a transparent PNG for the final image.
What I do is I just set height and width of image to 0.. Like this
[myImageView setFrame:CGRectMake(myX, myY, 0, 0)];