Iphone 设置UILabel不平滑的动画
我正在尝试设置UIlabel的动画,使其先变大,然后收缩回其原始帧。按预期扩大工作,但不缩小。当我用下面的代码收缩标签时,首先调整大小,然后再移动原点。这会导致两步动画不平滑 这是我的密码:Iphone 设置UILabel不平滑的动画,iphone,objective-c,Iphone,Objective C,我正在尝试设置UIlabel的动画,使其先变大,然后收缩回其原始帧。按预期扩大工作,但不缩小。当我用下面的代码收缩标签时,首先调整大小,然后再移动原点。这会导致两步动画不平滑 这是我的密码: CGRect rect = label.frame; [UIView animateWithDuration:.2 delay: 0.1 options: UIViewAnimationOptionBeginFromCurr
CGRect rect = label.frame;
[UIView animateWithDuration:.2
delay: 0.1
options: UIViewAnimationOptionBeginFromCurrentState
animations:^{
label.frame = CGRectMake(rect.origin.x + 4,
rect.origin.y + 4,
rect.size.width-8,
rect.size.height-8);
}
completion:^(BOOL finished){
}];
可以尝试对动画块内的标签应用变换,而不是调整矩形。类似于生长/收缩动画的以下行:
label.transform = CGAffineTransformMakeScale(1.5, 1.5); //grow
label.transform = CGAffineTransformMakeScale(1, 1); //shrink
请试用这个解决方案,我想这就是你想要的。我已经测试了它的工作,但请尝试让我知道,如果你正在寻找这个或没有
-(IBAction)growanimate:(id)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(shrinkanimate)];
label.transform = CGAffineTransformMakeScale(2.0f, 2.0f); //This will double label from current size.
[UIView commitAnimations];
}
-(void)shrinkanimate
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
label.transform = CGAffineTransformMakeScale(1.0f, 1.0f); //This will get it back to original size.
[UIView commitAnimations];
}
我猜问题是由调整帧大小触发调整大小通知这一事实引起的。缩小时可能会有更多的中断,因为superview显示了新的区域 在这种情况下,变换方法要好得多 我还猜测,使用transform方法,glyph路径和布局(换行符等)不会重新计算,缓存的CGPath只会在渲染时进行转换
关于定心问题,我看不出有什么问题 我想补充一点,如果你打算广泛使用这个效果,你可以为这个效果创建一个静态类,或者包含几个预设动画,里面有静态存储的变换 然后调用[MyPopEffect-popView:mylabel] 它避免了创建和发布转换,并允许在任何视图或其他项目中即时使用 无论如何,这是动画代码。。。干杯 [
]您没有进行转换。为什么要使用
UIViewAnimationOptionTransitionNone
?不要忘了给出奖励:)thx..以获得更详细的版本,但更早得到答案
UIView animateWithDuration:0.5f delay: 0.0f
options:UIViewAnimationOptionCurveEaseOut+UIViewAnimationOptionBeginFromCurrentState
animations:^{
label.transform=CGAffineTransformMakeScale(2.0f,2.0f);
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.5f delay: 0.0f
options:UIViewAnimationOptionCurveEaseIn+UIViewAnimationOptionBeginFromCurrentState
animations:^{
label.transform=CGAffineTransformMakeScale(1.0f,1.0f);
}
completion:^(BOOL finished){}];
}];