I try to use a ArrayWithObjects to create a scroll's movement.
And I have a problem, my animation is stopped and repeat at the number nine :/
This is my code :
background.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:#"background_wall2.png"], [UIImage imageNamed:#"background_wall3.png"], [UIImage imageNamed:#"background_wall4.png"], [UIImage imageNamed:#"background_wall5.png"], [UIImage imageNamed:#"background_wall6.png"], [UIImage imageNamed:#"background_wall7.png"], [UIImage imageNamed:#"background_wall8.png"], [UIImage imageNamed:#"background_wall9.png"], [UIImage imageNamed:#"background_wall10.png"], [UIImage imageNamed:#"background_wall11.png"], [UIImage imageNamed:#"background_wall12.png"], [UIImage imageNamed:#"background_wall13.png"], [UIImage imageNamed:#"background_wall14.png"], [UIImage imageNamed:#"background_wall15.png"], [UIImage imageNamed:#"background_wall16.png"], [UIImage imageNamed:#"background_wall17.png"], [UIImage imageNamed:#"background_wall18.png"], [UIImage imageNamed:#"background_wall19.png"], [UIImage imageNamed:#"background_wall20.png"], [UIImage imageNamed:#"background_wall21.png"], [UIImage imageNamed:#"background_wall22.png"], [UIImage imageNamed:#"background_wall23.png"], [UIImage imageNamed:#"background_wall24.png"], [UIImage imageNamed:#"background_wall.png"], nil];
[background setAnimationRepeatCount:0];
background.animationDuration = 0.3;
[background startAnimating];
Can you help me please ?
Thanks in advance
PS : Sorry for my bad English
Your animationDuration is too small. You are forcing the object to present all your frame faster than its max possibility.
From the Apple documentation:
The time duration is measured in seconds. The default value of this
property is equal to the number of images multiplied by 1/30th of a
second. Thus, if you had 30 images, the value would be 1 second.
This means that if you have 24 images, at least you have to set 0.8 as duration. (24 / 30).
Related
I recently just upgraded to xcode 6 and suddenly a bunch of my code in my app doesn't work. What happened originally was if you touched to the left of the screen, your character would face the left, and if you touched to the right he would face the right. When a certain interaction happened, there would be a method that would check whether or not he was looking to the left or right and the animation would correspond accordingly. Now in XCode 6, he can look to the left but play the animation that correlates to the right, and when I click to the left again, he briefly looks to the left and then will only play the right animation. I have a sample of the part of the code I think that is malfunctioning, but I can't seem to troubleshoot why.
if (Stickman.image == [UIImage imageNamed:#"BjLeft6.png"])
{
Stickman.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"BjLeft2.png"],
[UIImage imageNamed:#"BjLeft2.png"],
[UIImage imageNamed:#"BjLeft3.png"],
[UIImage imageNamed:#"BjLeft4.png"],
[UIImage imageNamed:#"BjLeft4.png"],
[UIImage imageNamed:#"BjLeft4.png"],
[UIImage imageNamed:#"BjLeft5.png"],
[UIImage imageNamed:#"BjLeft6.png"],
[UIImage imageNamed:#"BjLeft5.png"],
[UIImage imageNamed:#"BjLeft4.png"],
[UIImage imageNamed:#"BjLeft3.png"],
[UIImage imageNamed:#"BjLeft2.png"],
[UIImage imageNamed:#"BjLeft1.png"], nil];
[Stickman setAnimationRepeatCount:1];
Stickman.animationDuration = .5;
[Stickman startAnimating];
}
else
{
Stickman.image = [UIImage imageNamed:#"BjRight6.png"];
Stickman.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"BjRight2.png"],
[UIImage imageNamed:#"BjRight2.png"],
[UIImage imageNamed:#"BjRight3.png"],
[UIImage imageNamed:#"BjRight4.png"],
[UIImage imageNamed:#"BjRight4.png"],
[UIImage imageNamed:#"BjRight4.png"],
[UIImage imageNamed:#"BjRight5.png"],
[UIImage imageNamed:#"BjRight6.png"],
[UIImage imageNamed:#"BjRight5.png"],
[UIImage imageNamed:#"BjRight4.png"],
[UIImage imageNamed:#"BjRight3.png"],
[UIImage imageNamed:#"BjRight2.png"],
[UIImage imageNamed:#"BjRight1.png"], nil];
[Stickman setAnimationRepeatCount:1];
Stickman.animationDuration = .5;
[Stickman startAnimating];
}
The comparison is bad:
(Stickman.image == [UIImage imageNamed:#"BjLeft6.png"])
This is comparing addresses and UIImage imageNamed may not return the same instance of the image as Stickman.image received and == will fail.
Rarely is comparing instance addresses the correct solution when comparing for equality.
In our iOS app, we want a loading image which is just our logo, animated. I'm wondering what the best practice is to do this? Would it be to use a series of .png images, or one long .png image. I can also thing of using a .gif but the colour quality is not the greatest.
It may also be possible, since the animation is just resizing of certain elements, to do the animation programatically using several UIimages and resizing them, though it may not be as smooth.
UIImage* img1 = [UIImage imageNamed:#"image_1.png"];
UIImage* img2 = [UIImage imageNamed:#"image_2.png"];
UIImage* img3 = [UIImage imageNamed:#"image_3.png"];
UIImage* img4 = [UIImage imageNamed:#"image_4.png"];
UIImage* img5 = [UIImage imageNamed:#"image_5.png"];
NSArray *images = [NSArray arrayWithObjects:img1,img2,img3,img4,img5,nil];
UIImageView* imageView = [[UIImageView alloc]
initWithFrame:CGRectMake((self.view.frame.size.width-80)/2, 50, 80.0, 80.0)];
[imageView setAnimationImages:images];
[imageView setAnimationRepeatCount:100];
[imageView setAnimationDuration:3.0];
[imageView startAnimating];
imageView.tag = 100;
[self.view addSubview:imageView];
In my app you press a button and it plays an animation frame 1,2,3,4,5,6,7,8,9,10.
However what I want is basically pressing the button for 0.2 seconds plays frames 1,2,3 but pressing it for 0.5 seconds plays frames 1,2,3,4,5,6 etc...The more frames are played the longer you hold the button. I want this with the sound that plays when you press the same button i.e.play first 0.2 seconds of the sound with 0.2 seconds of the button pressed etc..
I am really struggling to get this to work on find a good tutorial because I am just a beginner. So please help but remember to explain with as much instruction as possible. Here is my code:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController {
}
- (IBAction)Button {
AudioServicesPlaySystemSound(SoundID);
}
-(IBAction)startanimating{
animatedimage.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"frames_00.png"],
[UIImage imageNamed:#"frames_05.png"],
[UIImage imageNamed:#"frames_10.png"],
[UIImage imageNamed:#"frames_15.png"],
[UIImage imageNamed:#"frames_20.png"],
[UIImage imageNamed:#"frames_25.png"],
[UIImage imageNamed:#"frames_30.png"],
[UIImage imageNamed:#"frames_35.png"],
[UIImage imageNamed:#"frames_40.png"],
[UIImage imageNamed:#"frames_45.png"],
[UIImage imageNamed:#"frames_50.png"],
[UIImage imageNamed:#"frames_50.png"],
[UIImage imageNamed:#"frames_45.png"],
[UIImage imageNamed:#"frames_45.png"],
[UIImage imageNamed:#"frames_45.png"],
[UIImage imageNamed:#"frames_40.png"],
[UIImage imageNamed:#"frames_40.png"],
[UIImage imageNamed:#"frames_40.png"],
[UIImage imageNamed:#"frames_40.png"],
[UIImage imageNamed:#"frames_40.png"],
[UIImage imageNamed:#"frames_40.png"],
[UIImage imageNamed:#"frames_40.png"],
[UIImage imageNamed:#"frames_35.png"],
[UIImage imageNamed:#"frames_35.png"],
[UIImage imageNamed:#"frames_35.png"],
[UIImage imageNamed:#"frames_30.png"],
[UIImage imageNamed:#"frames_30.png"],
[UIImage imageNamed:#"frames_30.png"],
[UIImage imageNamed:#"frames_25.png"],
[UIImage imageNamed:#"frames_25.png"],
[UIImage imageNamed:#"frames_25.png"],
[UIImage imageNamed:#"frames_25.png"],
[UIImage imageNamed:#"frames_25.png"],
[UIImage imageNamed:#"frames_25.png"],
[UIImage imageNamed:#"frames_20.png"],
[UIImage imageNamed:#"frames_20.png"],
[UIImage imageNamed:#"frames_20.png"],
[UIImage imageNamed:#"frames_15.png"],
[UIImage imageNamed:#"frames_15.png"],
[UIImage imageNamed:#"frames_15.png"],
[UIImage imageNamed:#"frames_10.png"],
[UIImage imageNamed:#"frames_10.png"],
[UIImage imageNamed:#"frames_10.png"],
[UIImage imageNamed:#"frames_05.png"],
[UIImage imageNamed:#"frames_05.png"],
[UIImage imageNamed:#"frames_05.png"],
[UIImage imageNamed:#"frames_00.png"],nil];
[animatedimage setAnimationRepeatCount:1];
animatedimage.animationDuration = 0.7;
[animatedimage startAnimating];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSURL *buttonURL = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:#"AVTREV" ofType:#"mp3"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)buttonURL, &SoundID);
{
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I have also heard I should use CALayers and CAanimation for this, would this be better? if so please provide help on how I can use CA and how to implement the button duration thing. Thank you I will really appreciate the help! :D
(This is not a repost, sorry for the confusion, This post is more focused on the animation and better articulated.
First declare a class property to hold your time.
Then:
UIButton * myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(100.0, 100.0, 100.0, 20.0);
[myButton setTitle:#"Test" forState:UIControlStateNormal];
[myButton addTarget:self action:#selector(userEndsTap:) forControlEvents:UIControlEventTouchUpInside];
[myButton addTarget:self action:#selector(userStartsTap:) forControlEvents:UIControlEventTouchDown];
- (void)userStartsTap:(id)sender {
// start time measurement
}
- (void)userEndsTap:(id)sender {
// stop time measurement, get duration and execute code according to time passed
}
I have found posts that concern with UIButton with Animation Image.
However i didn't found any solutions.
Here is my code.
UIImage *imageOne=[UIImage imageNamed:#"1Ads.png"];
UIImage *imageTwo=[UIImage imageNamed:#"2Ads.png"];
UIImage *imageThree=[UIImage imageNamed:#"3Ads.png"];
NSArray *arr = [[NSArray alloc] initWithObjects:imageOne,imageTwo,imageThree, nil];
self.btnAds.imageView.animationDuration = 7.0;
self.btnAds.imageView.animationImages = arr;
[self.btnAds.imageView startAnimating];
It's doesn't showing anything in View.
How can i do it?
Use the imageView property of UIButton. You can create an animation like this:
[myButton setImage:[UIImage imageNamed:#"1.png"] forState:UIControlStateNormal];
myButton.imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"1.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
[UIImage imageNamed:#"4.png"],
[UIImage imageNamed:#"5.png"],
nil];
myButton.imageView.animationDuration = 0.5;
[myButton.imageView startAnimating];
I want to add a array of UIImages to UIImageView using NSTimer. Such that it will be like an animation. How to do it in iOS?
Thanks in advance.
There is a very simple way to do it.
// create the view that will execute our animation
UIImageView* campFireView = [[UIImageView alloc] initWithFrame:self.view.frame];
// load all the frames of our animation
campFireView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"campFire01.gif"],
[UIImage imageNamed:#"campFire02.gif"],
[UIImage imageNamed:#"campFire03.gif"],
[UIImage imageNamed:#"campFire04.gif"],
[UIImage imageNamed:#"campFire05.gif"],
[UIImage imageNamed:#"campFire06.gif"],
[UIImage imageNamed:#"campFire07.gif"],
[UIImage imageNamed:#"campFire08.gif"],
[UIImage imageNamed:#"campFire09.gif"],
[UIImage imageNamed:#"campFire10.gif"],
[UIImage imageNamed:#"campFire11.gif"],
[UIImage imageNamed:#"campFire12.gif"],
[UIImage imageNamed:#"campFire13.gif"],
[UIImage imageNamed:#"campFire14.gif"],
[UIImage imageNamed:#"campFire15.gif"],
[UIImage imageNamed:#"campFire16.gif"],
[UIImage imageNamed:#"campFire17.gif"], nil];
// all frames will execute in 1.75 seconds
campFireView.animationDuration = 1.75;
// repeat the annimation forever
campFireView.animationRepeatCount = 0;
// start animating
[campFireView startAnimating];
// add the animation view to the main window
[self.view addSubview:campFireView];
Source: http://web.archive.org/web/20120305060003/http://appsamuck.com/day2.html