gpt4 book ai didi

ios - UILabel动画上下

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:08:31 24 4
gpt4 key购买 nike

我有这个 UILabel 动画,可以为倒数计时器设置动画。它工作正常,但是......

现在,它已设置好,因此文本使用 CATransition kCATransitionFromBottom 从顶部缓入。这需要 0.5 秒。我怎样才能让它在接下来的 0.5 秒内,CATransition 和我的标签缓和到底部?

希望你明白!谢谢!

这是一个视频,展示了动画现在的样子: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];
}
}

最佳答案

要使标签上下动画,我通常会这样做:

[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];
}];

这就是你要找的吗?

编辑

对,再看一遍你的问题,所以你想从顶部滑动淡入,然后滑动淡出到底部?

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、宽度、高度属性应用的。因此,在 y 中平移 100 个单位意味着您框架的原始 Y 坐标 + 100。

关于ios - UILabel动画上下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21848864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com