【发布时间】:2012-02-27 02:47:18
【问题描述】:
我有一个 UIView,我想改变它的背景颜色。使用UIView beginAnimation:context: 方法效果很好。但是,动画“持续”大约 1 秒。我希望它持续 5 秒。这是我正在使用的代码:
- (void)updateSky:(NSString *)time {
[UIView beginAnimations: @"backgroundUpdate" context:nil];
[UIView setAnimationDuration: 5.0];
gradient.colors = [NSArray arrayWithObjects: (id)[[UIColor colorWithRed:0x63/255.0f green:0xA9/255.0f blue:0xFF/255.0f alpha:1.0] CGColor],
(id)[[UIColor colorWithRed:0x8C/255.0f green:0xBF/255.0f blue:0xFF/255.0f alpha:1.0] CGColor], nil];
if(time == @"night") {
gradient.colors = [NSArray arrayWithObjects: (id)[[UIColor colorWithRed:0x1E/255.0f green:0x1E/255.0f blue:0x1E/255.0f alpha:1.0] CGColor],
(id)[[UIColor colorWithRed:0x2C/255.0f green:0x4C/255.0f blue:0x72/255.0f alpha:1.0] CGColor], nil];
}
[UIView commitAnimations];
}
gradient定义如下:
CAGradientLayer *gradient;
我做错了吗?
【问题讨论】: