Ios UILabel始终设置同一点的动画
我有一个名为“nameLabel”的UILabel,我把它放在动画块中,这样就发生了:Ios UILabel始终设置同一点的动画,ios,uilabel,Ios,Uilabel,我有一个名为“nameLabel”的UILabel,我把它放在动画块中,这样就发生了: _nameLabel.alpha = 1; CGAffineTransform translate = CGAffineTransformMakeTranslation(50, 50); _nameLabel.transform = translate; 我以为这会将UILabel动画化到我指定的位置,但它只是从上面的位置动画化到界面生成器中的位置。这里有什么帮助吗?可以发布动画块和其他相关代码吗?我不确定
_nameLabel.alpha = 1;
CGAffineTransform translate = CGAffineTransformMakeTranslation(50, 50);
_nameLabel.transform = translate;
我以为这会将UILabel动画化到我指定的位置,但它只是从上面的位置动画化到界面生成器中的位置。这里有什么帮助吗?可以发布动画块和其他相关代码吗?我不确定CGAffineTransformMakeTransform对标签做了什么,但如果要设置帧位置的动画,可以使用以下方法:
CGRect frame = _nameLabel.frame;
frame.origin.y = 100; //Desired height, origin.x can be modified as well.
//You can also change the frame size here but it wont work on UILabels, you will need `CGAffineTransformScale` for that.
[UIView animateWithDuration: 1.5
delay:0.0
options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState
animations:^ {
[_nameLabel setFrame:frame];
}
completion:^ (BOOL finished) {
}];
编辑:另一种方式:
CGRect frame = _nameLabel.frame;
frame.origin.y = 100;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];
[_nameLabel setFrame: newFrame];
[UIView commitAnimations];
当前状态可能是标签的当前位置,请首先尝试,但如果没有发生任何情况,请删除
UIViewAnimationOptionBeginFromCurrentState
,或将标签的帧设置到动画之前的另一个位置,并将其移到动画块中的初始位置(xib文件中的位置),这是您的调用 小心,因为自动布局会导致很多问题
尝试取消选择“使用自动布局”
它解决了我在翻译对象时遇到的所有问题。上面的代码会将标签向下和向右移动50个点。您希望发生什么?不幸的是,我正在使用带有[UIView beginAnimates:@“animation”上下文:NULL]的动画块;但你的解决方案就是我之前用的。我就是不能按我的方式工作。谢谢你的帮助。