我们如何设置UILabel
的宽度动画,以便仅使用UIView
animateWithDuration
增加和减少宽度
感谢您的帮助(此时我很沮丧,因为我一直试图这样做但是它不起作用)
答案 0 :(得分:2)
您可以在UIView动画块中设置UILabel
的帧。像这样:
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
}];
显然,您输入的尺寸取决于您的应用,并且可能会根据内容进行计算。
答案 1 :(得分:0)
尝试使用动画增加和减少帧宽,如下所示
// 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];
答案 2 :(得分:0)
试试这个
[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);
}];
}];
答案 3 :(得分:0)
最终在iOS 5.0中使用块
这样做了 [UIView animateWithDuration:2. delay:0 options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionBeginFromCurrentState animations:^{
[self.messageLabel setFrame:CGRectMake(90, 0, labelSize.width, 90)];
} completion:^(BOOL finished) {
}];
答案 4 :(得分:0)
我能够以这种方式做到这一点。 self指的是我添加标签的视图。在init中,添加宽度为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) {
}];
}];
}];