Shinurag KR
Shinurag KR

Reputation: 141

ios bottom up animation

how to animate a UILabel from bottom to up in iOS, i did this in android like this

Animation bottomUp = AnimationUtils.loadAnimation(_activity, R.drawable.bottom_up);
txtTitle.startAnimation(bottomUp);

bottom_up.xml

<?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android">
   <translate android:fromYDelta="75%p" android:toYDelta="0%p" 
    android:fillAfter="true"
 android:duration="600"/>
</set>

is there any idea to do the same in iOS also?

Hi all thanks for your help. i figured it out in this way.

 CATransition *Sidetransition=[CATransition animation];
 Sidetransition.duration=0.7;
 Sidetransition.type=kCATransitionMoveIn;
 Sidetransition.subtype=kCATransitionFromTop;
 [lblTitle.layer addAnimation:Sidetransition forKey:nil];

Thanks.

Upvotes: 1

Views: 821

Answers (1)

Mani
Mani

Reputation: 17595

Add layer animation to label which is make movement up and down. Use below code. It may useful to you..

-(void)addUpDownAnimationForButton:(UILabel*)label
{      
    CABasicAnimation *moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
    moveAnimation.duration = 5.0;
    moveAnimation.repeatCount=HUGE_VALF;
    moveAnimation.autoreverses=YES;
    moveAnimation.fromValue= [NSValue valueWithCGPoint:CGPointMake(self.view.frame.size.width/2, 0.0)];
    moveAnimation.toValue=[NSValue valueWithCGPoint:CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height)];
    [label.layer addAnimation:moveAnimation forKey:@"animatePosition"];
}

If you want remove this animation, remove animation from layer by

-(void)removeUpDownAnimationForButton:(UILabel*)label
{
    [label.layer removeAnimationForKey:@"animatePosition"];
}

Upvotes: 2

Related Questions