我们如何对UILabel
' 的宽度进行动画处理,以便仅使用UIView
animateWithDuration
感谢您的帮助(此时我很沮丧,因为我一直在尝试这样做,但它不起作用)
您可以设置UILabel
UIView 动画块内部的框架。像这样的东西:
CGRect originalFrame = self.address.frame;
[UIView animateWithDuration:0.3
animations:^{
self.myLabel.frame = CGRectMake(0, 0, 100, 100);
}
completion:^(BOOL finished) {
// use similar UIView animation to resize back to original
}];
显然,您输入的尺寸将取决于您的应用程序,并且可能会根据内容进行计算。
终于在 iOS 5.0 中用积木做到了这一点
[UIView animateWithDuration:2. delay:0 options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionBeginFromCurrentState animations:^{
[self.messageLabel setFrame:CGRectMake(90, 0, labelSize.width, 90)];
} completion:^(BOOL finished) {
}];
我能够以这种方式做到这一点。self 指的是我在其中添加标签的视图。在初始化中,添加宽度为 1 px 的标签。然后使用下面的.. UIViewAnimationOptionBeginFromCurrentState 允许它像门一样打开 PHEW!
[UIView animateWithDuration:1. delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
[self setFrame:CGRectMake(self.frame.origin.x-labelSize.width-PADDING, self.frame.origin.y, self.frame.size.width+labelSize.width+PADDING, self.frame.size.height)];
[self.messageLabel setFrame:CGRectMake(95, 10, labelSize.width, labelSize.height)];
self.messageLabel.alpha = 1;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1. delay:2. options:0 animations:^{
self.messageLabel.alpha = 0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1. delay:0. options:0 animations:^{
[self setFrame:CGRectMake(self.frame.origin.x+labelSize.width+PADDING, self.frame.origin.y, self.frame.size.width-labelSize.width-PADDING, self.frame.size.height)];
} completion:^(BOOL finished) {
}];
}];
}];
尝试使用如下动画增加和减少帧宽度
// original label frame CGRectMake( 0,0, 100,60 );
[UIView beginAnimations: @"moveLogo" context: nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:4];
//increasing frame width
label.frame = CGRectMake( 0,0, 400,60 );
[UIView commitAnimations];
尝试这个
[UIView animateWithDuration:0.6 animations:^(void)
{
self.label.bounds = CGRectMake(100, 100, 200, 100);
}completion:^(BOOL finished) {
[UIView animateWithDuration:0.6 animations:^(void)
{
self.label.bounds = CGRectMake(100, 100, 100, 100);
}];
}];