开发者

UIView animation terminates prematurely

开发者 https://www.devze.com 2023-03-17 21:39 出处:网络
I\'m trying to use the +[UIView animateWithDuration:animations:] method to animate a UITableViewCell\'s background colour from white to red. However, the colour will not animate, it immediately jumps

I'm trying to use the +[UIView animateWithDuration:animations:] method to animate a UITableViewCell's background colour from white to red. However, the colour will not animate, it immediately jumps to red. I've switched out setBackgroundColor: for setOpacity: and that works fine. What could be causing the animation to fail using background colour? Below is the code I'm u开发者_运维知识库sing:

UITableView * tableView = (UITableView *)[self view];
[UIView animateWithDuration:0.2 animations:^{
  [[tableView cellForRowAtIndexPath:
    [NSIndexPath indexPathForRow:0 inSection:0]] 
      setBackgroundColor:[UIColor redColor]];
}];


You cannot animate changes to color properties. You will have to create two background views and fade between them using their .alpha properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号