Ios UIView动画运行不正常
我有一个UIButton(大小100100),带有文本和彩色背景。当按下按钮时,我希望文本立即消失,并将按钮的大小(动画)更改为10001000。以下是我正在使用的代码:Ios UIView动画运行不正常,ios,objective-c,iphone,uiview,Ios,Objective C,Iphone,Uiview,我有一个UIButton(大小100100),带有文本和彩色背景。当按下按钮时,我希望文本立即消失,并将按钮的大小(动画)更改为10001000。以下是我正在使用的代码: [myButton setTitleColor:[UIColor colorWithRed:195/255.0f green:255/255.0f blue:180/255.0f alpha:0.0f] forState:UIControlStateNormal]; [UIView animateWithDu
[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,然后动画设置为100100。当我用setTitle:@“
替换setTitleColor
时,也会发生这种情况。我也尝试过改变动画中的文字或颜色,效果也一样
我觉得很明显我错过了什么,但我似乎看不到
编辑:如果我不运行动画,只是自己执行
setTitleColor
或setTitle:@“
,则文本将按预期消失,按钮大小保持不变 如果要保留使用UIKit设置按钮样式的方式,只需修改动画块中的层,而不是视图
button.layer.transform = CATransform3DMakeScale(10,10,1)
也许使用视图的transform
属性就足够了
button.transform = CGAffineTransformMakeScale(10,10)
NB 10只是一个任意大的值。请尝试使用setFrameThat,而不是setbounds!不知何故,我没有想到仅仅与图层交互。谢谢