ios - Xcode5 - 自动切换按钮边框颜色

标签 ios objective-c

我是 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/

相关文章:

ios - 停止 AUGraph 的卡顿

ios - 构建应用程序时找不到 Cocoapods header

objective-c - 适用于 NSArray 中包含的字符串数量

ios - iOS 中的应用内购买 didFailWithError :

ios - 关闭 View 后执行的功能不能完全工作 IOS

ios - CocoaLumberjack 错误 : Symbol not found: _objc_storeStrong

ios - UIAlertController 泄漏

ios - 如何使用 Objective-C 移动多个对象

ios - 使用 AFNetworking SetImageWithURL 显示 UIActivityIndi​​cator

ios - 减少 uibarbuttonitem 的宽度