Scripted-Sheep Development
Development, App´s und die Welt des Internets
  • Pages
    • About Us
  • Apps
  • Blog
Select Page ...

Blog

Pulsating UIView

Tim Specht 25. August 2011 App's No Comments

I needed to create a pulsating UIImageView (this will work for any subclass including itself of UIView without any changes) and solved that task using chained UIViewAnimation so I wanted to share that bunch of code with you.


//this method is used to setup all the stuff any initially starting the chain as mentioned

-(void)addLoadingImage{

UIImageView* pulseView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myImage.png"]];

pulseView.tag = MY_PULSE_TAG; //needed to keep track of the view afterwards, change this to whatever you want (use #define for better style, this is just a quick writedown!)

[self.view addSubview:pulseView];

[self pulseBig];

}

//animating the pulsing to big by changing the frame of the view which should be pulsing

-(void)pulseBig{

//needed to stop animation if view got removed, otherwhise we will get EXC_BAD_ACCESS

if(![self.view viewWithTag:MY_PULSE_TAG])

return;

[UIView beginAnimations:@"pulsing" context:nil];

[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

[UIView setAnimationDuration:1];

[UIView setAnimationDelegate:self];

[UIView setAnimationDidStopSelector:@selector(pulseSmall)];

[[self.view viewWithTag:MY_PULSE_TAG] setFrame:myBigFrame];

[UIView commitAnimations];

 

}

//pulsing the view small!

-(void)pulseSmall{

//needed to stop animation if view got removed, otherwhise we will get EXC_BAD_ACCESS

if(![self.view viewWithTag:MY_PULSE_TAG])

return;

[UIView beginAnimations:@"pulsing" context:nil];

[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

[UIView setAnimationDuration:1];

[UIView setAnimationDelegate:self];

[UIView setAnimationDidStopSelector:@selector(pulseSmall)];

[[self.view viewWithTag:MY_PULSE_TAG] setFrame:mySmallFrame];

[UIView commitAnimations];

}

 

Just fill in your two frames and the tag and you are ready to go. Please be aware that you need to set the origin of the bigger frame half of the changed size to be sure the center remains the same.

Share on Facebook

← Customizing UISearchBar
Tim Specht

Hinterlasse eine Antwort Antworten abbrechen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

CAPTCHA-Bild
Bild neuladen

*

  • Tim Specht

    • Berlin
    • tim (at) tim-specht (dot) de
  • Facebook
          • Copyright © 2012 Tim Specht. All Rights Reserved