我是 IOS 编程新手。 我想在应用程序启动时自动切换按钮边框颜色以引起用户注意, 我试过下面的代码,但只选择了最终颜色。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.0];
[UIView setAnimationDuration:3.0];
button.layer.borderWidth=2.5f;
button.layer.borderColor=[[UIColor blueColor]CGColor];
[UIView setAnimationDelay:3.0];
button.layer.borderColor=[[UIColor clearColor]CGColor];
[UIView setAnimationDelay:6.0];
button.layer.borderColor=[[UIColor redColor]CGColor];
[UIView commitAnimations];
}
最佳答案
您正在做的是一种无效的链接动画的方式。因此,只会应用最后的更改。此外,您应该使用基于 block 的动画,这是 Apple 从 iOS 4 开始推荐的。应该是这样的:
[UIView animateWithDuration:3.0 animations:^{
button.layer.borderWidth=2.5f;
button.layer.borderColor=[[UIColor blueColor]CGColor];
} completion:^(BOOL finished) {
[UIView animateWithDuration:3.0 animations:^{
button.layer.borderColor=[[UIColor clearColor]CGColor];
} completion:^(BOOL finished) {
[UIView animateWithDuration:3.0 animations:^{
button.layer.borderColor=[[UIColor redColor]CGColor];
}];
}];
}];
关于ios - Xcode5 - 自动切换按钮边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25538243/