UIView 动画表现不正常
UIView Animation not behaving properly
我有一个带有文本和彩色背景的 UIButton(大小 100,100)。按下按钮时,我希望文本立即消失,并且按钮将动画大小更改为 1000,1000。这是我正在使用的代码:
[myButton setTitleColor:[UIColor colorWithRed:195/255.0f green:255/255.0f blue:180/255.0f alpha:0.0f] forState:UIControlStateNormal];
[UIView animateWithDuration:2.0f
delay:1.0f
options:UIViewAnimationCurveEaseInOut
animations:^{
[myButton setBounds:CGRectMake(0, 0, 1000, 1000)];
}
completion:^(BOOL finished){
SetupView * sv = [[SetupView alloc] initWithNibName:nil bundle:nil];
//[self presentViewController:sv animated:NO completion:nil];
}
];
现在,如果我取出 setTitleColor
,按钮会很好地展开,但文本仍然存在(很明显)。但是,保持 setTitleColor
使按钮大小为 0,0,然后动画为 100,100。当我用 setTitle:@""
替换 setTitleColor
时也会发生这种情况。我也试过更改动画中的文本或颜色,结果相同。
我觉得我错过了一些明显的东西,但我似乎看不到它。
编辑:如果我不 运行 动画而只是自己做 setTitleColor
或 setTitle:@""
,文本会按预期消失,按钮保持相同大小。
如果您想保留使用 UIKit 设置按钮样式的方式,只需修改动画块中的层,而不是视图。
button.layer.transform = CATransform3DMakeScale(10,10,1)
也许使用视图的 transform
属性.
就足够了
button.transform = CGAffineTransformMakeScale(10,10)
注意 10 只是一个任意大的值。
我有一个带有文本和彩色背景的 UIButton(大小 100,100)。按下按钮时,我希望文本立即消失,并且按钮将动画大小更改为 1000,1000。这是我正在使用的代码:
[myButton setTitleColor:[UIColor colorWithRed:195/255.0f green:255/255.0f blue:180/255.0f alpha:0.0f] forState:UIControlStateNormal];
[UIView animateWithDuration:2.0f
delay:1.0f
options:UIViewAnimationCurveEaseInOut
animations:^{
[myButton setBounds:CGRectMake(0, 0, 1000, 1000)];
}
completion:^(BOOL finished){
SetupView * sv = [[SetupView alloc] initWithNibName:nil bundle:nil];
//[self presentViewController:sv animated:NO completion:nil];
}
];
现在,如果我取出 setTitleColor
,按钮会很好地展开,但文本仍然存在(很明显)。但是,保持 setTitleColor
使按钮大小为 0,0,然后动画为 100,100。当我用 setTitle:@""
替换 setTitleColor
时也会发生这种情况。我也试过更改动画中的文本或颜色,结果相同。
我觉得我错过了一些明显的东西,但我似乎看不到它。
编辑:如果我不 运行 动画而只是自己做 setTitleColor
或 setTitle:@""
,文本会按预期消失,按钮保持相同大小。
如果您想保留使用 UIKit 设置按钮样式的方式,只需修改动画块中的层,而不是视图。
button.layer.transform = CATransform3DMakeScale(10,10,1)
也许使用视图的 transform
属性.
button.transform = CGAffineTransformMakeScale(10,10)
注意 10 只是一个任意大的值。