Làm cách nào để mờ dần từ màu nền này sang màu khác trong UIView?Làm mờ màu nền từ màu này sang màu khác trong UIView
Trong javascript (jQuery) nó có thể được thực hiện bằng cách làm như sau:
$('body').animate({ backgroundColor: "#ff00ff"});
Nó sẽ được dễ dàng hơn nếu tôi chuyển đổi màu sắc để HSV?
CHỈNH SỬA: Đã cố gắng thực hiện điều đó bằng CABasicAnimation nhưng nó nhấp nháy màu trắng không rõ lý do. :/
CABasicAnimation* fade = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
fade.fillMode = kCAFillModeForwards;
fade.removedOnCompletion = NO;
// fade.fromValue = (id)[self.view backgroundColor].CGColor;
fade.toValue = (id)[UIColor greenColor].CGColor;
[self.view.layer addAnimation:fade forKey:@"fade"];
Sau đó, tôi đã cố gắng tìm cách khác để làm điều đó và tình cờ gặp "hoạt ảnh ngầm". Các công trình sau đây có phần mờ nhạt đẹp mắt trong một giây:
[UIView beginAnimations:@"fade" context:nil];
[UIView setAnimationDuration:1];
[[self view] setBackgroundColor: [UIColor greenColor]];
[UIView commitAnimations];
Cảm ơn, StackOverflow, để giúp mọi người tìm hiểu nhiều hơn. :)
trùng lặp: http://stackoverflow.com/questions/518192/how-do-you-explicitly-animate-a-calayers-backgroundcolor –