Animation one image to the next - iphone

I have a flash file and need to reprogram for iPhone.
The design of the app is a navbar with start buttom and an image view below them. I have 46 PNL images that I want to show in succession after the start button is clicked. Each picture will stay on the screen for 5 seconds.
I tried to replicate a code that I got off of YouTube but it did not work.
For the viewcontroller.h I used the following code verbatim and was able to link images (I call them ac) to the image view and also to establish a link for the start button:
{
IBOutlet UIImageView *ac;
}
-(IBAction)startclick:(id)sender;
For the viewcontroller.m I used the following concept but I received many syntax warnings:
NSarray
List of 46 png files using #" notation for string
Last png followed by nil
Then some notation for length that each image appears.
If someone could help me out with the viewcontroller.h and viewcontroller.m to command this sort of animation, it would be much appreciated.

You should use UIImageView's animationImages property to do this, with your button calling startAnimating and/or stopAnimating:
UIImage *frame1 = [UIImage imageNamed:#"frame1.png"];
UIImage *frame2 = [UIImage imageNamed:#"frame2.png"];
UIImage *frame3 = [UIImage imageNamed:#"frame2.png"];
UIImage *frame4 = [UIImage imageNamed:#"frame2.png"];
uiImageView.animationImages = [[NSArray alloc] initWithObjects:frame1, frame2, frame3, frame4, nil];
uiImageView.animationDuration = 1.0 // defaults is number of animation images * 1/30th of a second
uiImageView.animationRepeatCount = 5; // default is 0, which repeats indefinitely
[uiImageView startAnimating];
// [uiImageView stopAnimating];
If you can't work out the syntax of Objective-C, you're going to struggle to do pretty much anything related to iPhone development.

Related

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.

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 ?

iPhone: Image View picture size limit

Hey guys first I got a picture into a image view that was 2900x2100 and the file size was about 4MB I also had an scroll view to move around the image.
Anyways it crashed, first I though it was because the 4MB size. Then I resized it making it 1287x1234 and 1.3MB but it was pixelated when I zoom it too much.
After that I manage to make it 2900x2100 with 1.5 MB! so I ran it on my device and it still crashes!!
Anybody knows why's that?
This is what I get on the debugger console
Program received signal: “0”.
warning: check_safe_call: could not restore current frame
here's more info, this is my viewDidLoad method:
UIImageView *tempimage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"sanlucasFLAT.jpg"]];
self._FLatLucasImageView = tempimage;
[tempimage release];
_FLatLucasImageView.frame = CGRectMake(-7, 0, 800, 800);
_FLatLucasImageView.contentMode = UIViewContentModeScaleAspectFit;
_FlatLucasScrollView.contentSize = CGSizeMake(_FLatLucasImageView.frame.size.width,_FLatLucasImageView.frame.size.height);
_FlatLucasScrollView.delegate = self;
_FlatLucasScrollView.clipsToBounds = YES;
[_FlatLucasScrollView addSubview:_FLatLucasImageView];
[_FLatLucasImageView release];
When I set the CGRectMake to: (0,0,2900,2961) it doesn't crash when I scroll the image
Best Regards
Carlos Vargas
The reason why your app crashed is because the picture you are using is too big.
According to the class reference for UIImage, it says that You should avoid creating UIImage objects that are greater than 1024 x 1024 in size.
If you add a UIImage object which has a bigger image than 1024 x 1024 to a UIImageView object, your app could crash. If you are lucky, sometimes your app doesn't crash though.
The file size of your image doesn't really matter here: UIImage will have to decompress it and store the decompressed image in memory. It would usually need 4 bytes for each pixel, which means a 2900 x 2100 pixel image will take up more than 24 MB of memory. On an iPhone or iPhone 3G you might not even have that much memory available for your whole program.
Maybe try splitting it up into smaller images and then load them as necessary when the user scrolls around your view. Just cut it into tiles that are about 320x480 or so (the iPhone's screen size) and then only add the visible tiles to a UIScrollView, and remove them when the user scrolls away and they become invisible.
This code is very messy. Couple of things:
Try not to use instance variables with an underscore prefix (apple semi-private)
Try not to use instance variables start with a uppercase letter (convention, things start start with an uppercase letter are usually classes or types)
Do not define properties for instance variables that you do not actually expose. If they are simply things internal to your class then you do not need a property.
That being said, my guess is that you are over-releasing the image view. Try removing that last [_FLatLucasImageView release].
If you do not need to access that image view after you have added it to the scroll view then I suggest to completely remove the instance variable and property and simply have code like this:
UIImage* image = [UIImage imageNamed: #"sanlucasFLAT.jpg"];
if (image != nil)
{
UIImageView* imageView = [[[UIImageView alloc] initWithImage: image] autorelease];
if (imageView != nil)
{
imageView.frame = CGRectMake(-7, 0, 800, 800);
imageView.contentMode = UIViewContentModeScaleAspectFit;
flatLucasScrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
flatLucasScrollView.delegate = self;
flatLucasScrollView.clipsToBounds = YES;
[flatLucasScrollView addSubview: imageView];
}
}

UIImageview animation problem?

i have one imageview in IB.i linked it perfectly in my view controller's IBoutlet
which is as IB_img .i have done in my viewdidload as
self.IB_img.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"img_1.jpg"],
[UIImage imageNamed:#"img_2.jpg"],nil];
self.IB_img.animationDuration = 1;
self.IB_img.animationRepeatCount = 0;
[self.IB_img startAnimating];
it is not working perfectly....image is not in screen..but if i do it in without IB,in other words dynamically...it works perfectly...any help please to do animation with IB ?
You would have not set the Mose of the imageView as in required format.
You can do it as:
Try to set the one of the animation images as the image of your image view in xib(temporarily).
then set the image view's mode as strecthtofit or whatever suits you. now remove the image. and build you will see the image in proper position.

How do I use an animated .gif in my iPhone application?

I have an animated gif file that I want to use in my iPhone application, but the animation doesn't work. Does anybody know how to fix it?
If you have a serie of images you want to animate you can easily do it with UIImageView:
UIImage *blur5 = [UIImage imageNamed:#"blur5.png"];
UIImage *blur6 = [UIImage imageNamed:#"blur6.png"];
self.imageView.animationImages = [[NSArray alloc] initWithObjects:blur5, blur6, nil];
self.imageView.animationRepeatCount = 5;
[self.imageView startAnimating];
I found this easier than trying to use UIWebView.
UIWebView does not properly display all GIF content. You need to use a UIImageView, but the iPhone OS does not support animated GIFS and only displays the first frame.
So you need to extract all of the other frames first.
Crude example code here:
http://pliep.nl/blog/2009/04/iphone_developer_decoding_an_animated_gif_image_in_objc
You can use source at http://blog.stijnspijker.nl/2009/07/animated-and-transparent-gifs-for-iphone-made-easy/
It has a GIF decoder that you can use directly to get solution.
I successfully used it. But it have some problems with transparency.
This can be achieved by this piece of code:
NSArray * imageArray = [[NSArray alloc] initWithObjects:[UIImage imageNamed:#"1.png"], [UIImage imageNamed:#"2.png"], nil]; //this will be the frames of animation images in sequence.
ringImage = [[UIImageView alloc]initWithFrame:CGRectMake(100,200,600,600)];
ringImage.animationImages = imageArray;
ringImage.animationDuration = 1.5;//this the animating speed which you can modify
ringImage.contentMode = UIViewContentModeScaleAspectFill;
[ringImage startAnimating];//this method actually does the work of animating your frames.
I know its an old thread..but may be helpful for someone..:)
One other option is to decode the gif in your application, and then "frame serve" it to a OpenGL object. This way is less likely to run out of memory for large gifs.