i tried to make this slideshow repeat for infinity and didn't work.please help me
-(void)viewDidLoad
{
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:15 target:self selector:#selector(changeImage) userInfo:nil repeats:YES];
}
-(void)changeImage
{
[UIView transitionWithView:imageView duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
imageView.image = [UIImage imageNamed:#"6.png"];
} completion:^(BOOL done){
[UIView transitionWithView:imageView duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
imageView.image = [UIImage imageNamed:#"2.png"];
} completion:^(BOOL done){
[UIView transitionWithView:imageView duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
imageView.image = [UIImage imageNamed:#"3.png"];
} completion:^(BOOL done){
}];
}];
}];
}
Rather than Doing this You can use inbuilt property of UIImageview for animation images.
You can try Something Like,
NSArray *images = [NSArray arrayWithObjects:
[UIImage imageNamed:#"6.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
nil];
imageView.animationImages = images;
imageView.animationDuration = 1;
imageView.animationRepeatCount = 0; // 0 = nonStop repeat
[imageView startAnimating];
You can get this from example : http://goo.gl/8Gj6m0
Related
In my app, I need to set up an animation that will run on repeat until I perform an action on it. I want both an image to change, and text change along with it. I am trying now the suggested key frame animations, but it is only showing the last change and no repeats. I have done some searches and looking at the documentation, but I'm definitely still missing something.
It was my understanding that the animateKeyframesWithDuration is measured in seconds, while relative start and relative duration are 0 - 1 in value, so I set each to be 0.2, as there are 5, and 0.2 is exactly a fifth. What am I doing wrong? All of the NSLogs fire, but none of the events actually change, other than the final one.
[UIView animateKeyframesWithDuration:70 delay:0 options:UIViewKeyframeAnimationOptionRepeat animations:^{
[UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.2 animations:^{
NSLog(#"a1");
self.eventsText.text = nil;
theImageView.image = [UIImage imageNamed:#"welcome.png"];
}];
[UIView addKeyframeWithRelativeStartTime:0.2 relativeDuration:0.2 animations:^{
NSLog(#"a12");
theImageView.image = [UIImage imageNamed:#"pleasepray.png"];
self.eventsText.text = #"Test2";
}];
[UIView addKeyframeWithRelativeStartTime:0.4 relativeDuration:0.2 animations:^{
NSLog(#"a13");
theImageView.image = [UIImage imageNamed:#"comingevents.png"];
self.eventsText.text = #"Test3";
}];
[UIView addKeyframeWithRelativeStartTime:0.6 relativeDuration:0.2 animations:^{
NSLog(#"a14");
theImageView.image = [UIImage imageNamed:#"birthdays.png"];
self.eventsText.text = nil;
}];
[UIView addKeyframeWithRelativeStartTime:0.8 relativeDuration:0.2 animations:^{
NSLog(#"a14");
theImageView.image = [UIImage imageNamed:#"ournumbers.png"];
self.eventsText.text = #"Test4";
}];
} completion:nil];
Ok, so here's what I ended up doing. I only have 5 different "slides" that I need to rotate through, and some of them without text. For now, I put text into an Array to simulate what I need. In the future, this will be dynamic, pulled from a server. I then set up an NSInteger property to link everything together, and pull from this array to go along with how long each animation of the images takes.
-(void)announcementsTime {
[self rotatewarmup];
_timer = [NSTimer scheduledTimerWithTimeInterval:14.0 target:self selector:#selector(rotatewarmup )userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer: _timer forMode: NSDefaultRunLoopMode];
}
-(void)rotatewarmup
{
theImageView.hidden = NO;
NSArray *imagesArray = [NSArray arrayWithObjects:
[UIImage imageNamed:#"welcome.png"],
[UIImage imageNamed:#"pleasepray.png"],
[UIImage imageNamed:#"comingevents.png"],
[UIImage imageNamed:#"birthdays.png"],
[UIImage imageNamed:#"contribution2.png"],
nil];
if (self.songNumber == 0) {
if (_firingTime == 4) {
self.eventsText.text = self.allInfo[_firingTime];
theImageView.image = imagesArray[_firingTime];
_firingTime = 0;
}
else {
self.eventsText.text = self.allInfo[_firingTime];
theImageView.image = imagesArray[_firingTime];
NSInteger newFiring = _firingTime + 1;
_firingTime = newFiring;
}
}
else {
self.eventsText.text = #"";
}
}
i got a button to show an image in the UIImageView. what i need to do is to get this image to fade out by itself in 2 seconds, is it possible to do so?
here is my code on the button:
- (IBAction)A {
UIImage *Img = [UIImage imageNamed:#"AString.png"];
[ImageView setImage:Img];
}
thank you in advance...
Try this:
- (IBAction)A
{
UIImage *Img = [UIImage imageNamed:#"AString.png"];
[ImageView setImage:Img];
Img.hidden = NO;
Img.alpha = 1.0f;
[UIView animateWithDuration:2 delay:0 options:0 animations:^{
Img.alpha = 0.0f;
} completion:^(BOOL finished) {
Img.hidden = YES;
}];
}
Try this code :
yourImageView.hidden = YES;
[UIView transitionWithView:yourImageView
duration:2
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.view layoutIfNeeded]; // Called on parent view
}
completion:NULL];
I want to implement the next situation: step by step change image in uiImageView with UIViewAnimationOptionTransitionCrossDissolve animation.
I've tried the following:
[UIView transitionWithView:imageView
duration:2.0f
options: UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
animations:^{
imageView.image = [self.images objectAtIndex:self.currentIndex];
self.currentIndex ++;
if (self.currentIndex >2) self.currentIndex = 0;
} completion:^(BOOL finished) {
}];
But this does not even start animation.
The only thing makes it work - use recursion for that purpose:
- (void) switchBckgroundWithIndex: (NSInteger) index imageView: (UIImageView*) imageView
{
if (index >=[self.images count]) index = 0;
#weakify(self)
[UIView transitionWithView:imageView
duration:2.0f
options: UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionTransitionCrossDissolve
animations:^{
#strongify(self)
imageView.image = [self.images objectAtIndex:index];
} completion:^(BOOL finished) {
#strongify(self)
[self switchBckgroundWithIndex:index+1 imageView:imageView];
}];
}
How can i change images repeatedly with those animation effect without using recursion? Please, help me to find solution
I have used this method for animating images in UIImageView
-(void)viewDidLoad
{
[super viewDidLoad];
mutArr=[[NSMutableArray alloc]init];
[mutArr addObject:#"b1#2x.png"];
[mutArr addObject:#"b2#2x.png"];
[mutArr addObject:#"b3#2x.png"];
[mutArr addObject:#"b4#2x.png"];
NSTimer *timerForImage = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:#selector(animateImages) userInfo:nil repeats:YES];
}
-(void)animateImages
{
imageCount = imageCount + 1;
NSString *imageName =[NSString stringWithFormat:#"%#",[mutArr objectAtIndex:imageCount]];
if (imageCount==4)
{
imageCount=0;
}
_imgVw.image = [UIImage imageNamed:imageName];
CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[_imgVw.layer addAnimation:transition forKey:nil];
}
#interface abc ()
{
int imgCount;
}
then in -
- (void)viewDidLoad
{
[super viewDidLoad];
imgCount = 0;
[self animateAllImages];
}
- (void)animateAllImages
{
NSArray *animationImages = #[[UIImage imageNamed:#"Image1"], [UIImage imageNamed:#"Image2"],[UIImage imageNamed:#"Image3"],[UIImage imageNamed:#"Image4"]];
UIImage *image = [animationImages objectAtIndex:(imgCount % [animationImages count])];
[UIView transitionWithView:self.animationImageView
duration:0.8f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.animationImageView.image = image;
} completion:^(BOOL finished) {
[self animateAllImages];
imgCount++;
}];
}
Basically, I am trying to simulate an explosion that starts small but grows until it takes up the entire screen.
-(void)Dying{
[BirdMovement invalidate];
[TunnelMovement invalidate];
[TunnelMovement2 invalidate];
[TunnelMovement3 invalidate];
[TunnelMovement4 invalidate];
[BirdMovement_orange invalidate];
[BirdMovement_yellow invalidate];
[BirdMovement_green invalidate];
[BirdMovement_blue invalidate];
[self.window makeKeyAndVisible];
Bird.frame=CGRectMake(Bird.center.x,Bird.center.y,23,37);
Bird.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"Explode1.png"],
[UIImage imageNamed:#"Explode2.png"],
[UIImage imageNamed:#"Explode3.png"],
[UIImage imageNamed:#"Explode4.png"]
, nil];
Bird.animationDuration = 3;
Bird.animationRepeatCount = 1;
[Bird startAnimating];
[self.window addSubview:Bird];
[self performSelector:#selector(Dead) withObject:nil afterDelay:2.0];
}
-(void)Dead{
[Bird stopAnimating];
[self GameOver];
}
I tried messing with the CGRectMake saying things like
[Bird.frame=CGRectMake(Bird.center.x,Bird.center.y,23 +5 ,37 +5);]
But obviously this wont work cause its just making it (28, 42).
This will animate your imageView to your new size over 3 seconds.
UIImageView * bird = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
bird.animationImages = #[
[UIImage imageNamed:#"bird1"],
[UIImage imageNamed:#"bird2"],
[UIImage imageNamed:#"bird3"],
[UIImage imageNamed:#"bird4"],
[UIImage imageNamed:#"bird5"]
];
[self.view addSubview:bird];
[bird startAnimating];
[UIView animateWithDuration:2 animations:^{
bird.frame = CGRectMake(0, 0, 200, 200);
}];
hello i have this simple animation here that slides photos automatically.i just want to add extra effects on the slides thing like flipping or fading.please help me
- (void)viewDidLoad
{
[super viewDidLoad];
imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"6.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"], nil];
imageView.animationDuration = 15.00; //5 seconds each
imageView.animationRepeatCount = 0; //infinite
[imageView startAnimating]; //start the animation
}
To do that, you're going to need to go past UIImageView's animationImages property and manage the animations yourself using UIView transitionWithView and nest such. Like so.
[UIView transitionWithView:imageView duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
imageView.image = [UIImage imageNamed:#"6.png"];
} completion:^(BOOL done){
[UIView transitionWithView:imageView duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
imageView.image = [UIImage imageNamed:#"2.png"];
} completion:^(BOOL done){
[UIView transitionWithView:imageView duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
imageView.image = [UIImage imageNamed:#"3.png"];
} completion:^(BOOL done){
}];
}];
}];