IOS: simple animation

I want to create a simple animation that changes the alpha value:

[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:2]; [view1 setAlpha:0.00]; [UIView commitAnimations]; 

Ok, so I change the alpha value for two seconds, and it works fine, but I want this thing: When alpha is 0, the animation should start another time before alpha = 1 Thus, the animation should be: alpha 0 → alpha 1 → alpha 0 → alpha 1 → ... and so on for two seconds. Can you help me?

my complete code

 -(IBAction){ FirstViewController *firstViewController = [[[FirstViewController alloc] init]autorelease]; [firstViewController.label1 setAlpha:1.00]; [firstViewController.label2 setAlpha:1.00]; view = firstViewController.viewFirst; //this is my view and I copy in other view [self fadeOut:nil finished:nil context:nil];} - (void) fadeOut:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:2]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(fadeIn:finished:context:) ]; [view setAlpha:0.00]; [UIView commitAnimations]; } - (void) fadeIn:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:2]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(fadeOut:finished:context:) ]; [view setAlpha:1.00]; [UIView commitAnimations]; } 
+7
source share
5 answers
 - (void) fadeOut:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:2]; [UIView setAnimationDelegate:self]; if(animationRunning){ [UIView setAnimationDidStopSelector:@selector(fadeIn:finished:context:) ]; } [view1 setAlpha:0.00]; [UIView commitAnimations]; } - (void) fadeIn:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:2]; [UIView setAnimationDelegate:self]; if(animationRunning){ [UIView setAnimationDidStopSelector:@selector(fadeOut:finished:context:) ]; } [view1 setAlpha:1.00]; [UIView commitAnimations]; } 

They will call each other at the end of the animation ...

All you have to do to start casting the ball is a challenge:

 [self fadeOut:nil finished:nil context:nil]; 
+6
source

In iOS 4 and later, you can do

  view1.alpha = 1.0; [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionRepeat|UIViewAnimationAutoReverse animations:^{ view1.alpha = 0.0; } completion:nil ]; 
+10
source

You can set the animation completion handler (using the block-based API or +(void)setAnimationDidStopSelector:(SEL)selector ) and run the following.

Alternatively take a look at these methods:

 + setAnimationRepeatCount: + setAnimationRepeatAutoreverses: 
+3
source

I think you can use only one function (based on previous response functions):

 - (void) fadeIn:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:2]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(fadeIn:finished:context:) ]; [view1 setAlpha:mod(1-view1.alpha)]; [UIView commitAnimations]; } 

Alplha should not be a negative value, so the mod must be applied

0
source

You create a ViewController as shown below

 FirstViewController *firstViewController = [[[FirstViewController alloc] init]autorelease]; 

And then adding animation to it, but when you added firstViewController.view to the heirarchy view (addSubview). Also just calling

 [[[FirstViewController alloc] init]autorelease] 

do not create a label object unless you override its init method. Try debugging if the mark is selected at this point in time. Also for animation I use uiview anitmation with completion block method

0
source

All Articles