UILabel animation up and down

I have an animation UILabelthat animates a countdown timer. It works great, but ...

At the moment, it is configured so that the text is scaled down from above using CATransition kCATransitionFromBottom. It takes 0.5 seconds. How can I make it so that over the next 0.5 seconds CATransitionand my shortcut drops to the bottom?

I hope you understand! Thank!

Here's a video on how the animation looks right now: http://tinypic.com/r/5vst2h/8

-(void)updateLabel {

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int *units = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [calendar components:units fromDate:[NSDate date] toDate:destinationDate options:0];


    //ANIMASJON

secLabel.alpha = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

//don't forget to add delegate.....
[UIView setAnimationDelegate:self];

[UIView setAnimationDuration:0.5];
secLabel.alpha = 1;

//also call this before commit animations......
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

CATransition *animation = [CATransition animation];
animation.duration = 0.5;   //You can change this to any other duration
animation.type = kCATransitionMoveIn;     //I would assume this is what you want because you want to "animate up or down"
animation.subtype = kCATransitionFromBottom; //You can change this to kCATransitionFromBottom, kCATransitionFromLeft, or kCATransitionFromRight
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[secLabel.layer addAnimation:animation forKey:@"secLabel"];


[dayLabel setText:[NSString stringWithFormat:@"%02d%", [components day]]];
[hourLabel setText:[NSString stringWithFormat:@"%02d%", [components hour]]];
[minLabel setText:[NSString stringWithFormat:@"%02d%", [components minute]]];
[secLabel setText:[NSString stringWithFormat:@"%02d%", [components second]]];

[UIView commitAnimations];

}

-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished    context:(void *)context {
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    secLabel.alpha = 0;
    [UIView commitAnimations];
}
}
+3
source share
2 answers

To animate the shortcut up, down, I usually did this:

[UIView animateWithDuration:0.2
                      delay:0
                    options:UIViewAnimationOptionCurveEaseIn
                 animations:^{
                             // moves label up 100 units in the y axis
                             self.myLabel.transform = CGAffineTransformMakeTranslate(0, -100);
                         }
                 completion:^(BOOL finished) {
                     [UIView animateWithDuration:0.2
                                           delay:0
                                         options:UIViewAnimationOptionCurveEaseOut
                                      animations:^{
                                          // move label back down to its original position
                                          self.myLabel.transform = CGAffineTransformMakeTranslate(0,0);
                                      }
                                      completion:nil];
                  }];

Is this what you are looking for?

Edit

, , , ?

self.mylabel.alpha = 0;

[UIView animateWithDuration:0.2
                      delay:0
                    options:UIViewAnimationOptionCurveEaseIn
                 animations:^{
                             // moves label down 100 units in the y axis
                             self.myLabel.transform = CGAffineTransformMakeTranslate(0, 100);
                             // fade label in
                             self.myLabel.alpha = 1;
                         }
                 completion:^(BOOL finished) {
                     [UIView animateWithDuration:0.2
                                           delay:0
                                         options:UIViewAnimationOptionCurveEaseOut
                                      animations:^{
                                          // move label down further by 100 units
                                          self.myLabel.transform = CGAffineTransformMakeTranslate(0,1000);
                                          // fade label out
                                          self.myLabel.alpha = 0;
                                      }
                                      completion:nil];
                  }];

, x, y, width, height . , 100 y Y + 100.

+5

. , . - : ( y - )

[UIView animateWithDuration:0.5 animations:^{
        MyLbl.frame = CGRectMake(myLbl.frame.origin.x, 200, myLbl.frame.size.width, myLbl.frame.size.height); // 200 is considered to be center
        myLbl.alpha = 1;
    } completion:^(BOOL finished){
        [UIView animateWithDuration:0.5 animations:^{
            myLbl.frame = CGRectMake(myLbl.frame.origin.x, 400, myLbl.frame.size.width, myLbl.frame.size.height); // 400 is considered to be bottom somewhere
            myLbl.alpha = 0;
        }];
    }];

, .

+1

All Articles