In the new Single View application, the following code:
- (void)viewDidAppear:(BOOL)animated { self.fooView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)]; self.fooView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:self.fooView]; [UIView animateWithDuration:2 animations:^{ self.fooView.backgroundColor = [UIColor blueColor]; }]; }
will animate the yellow background to blue. fooView fair:
@property (strong, nonatomic) UIView *fooView;
But if a custom view class fooView is fooView , and I changed the above code, replacing UIView with fooView , and also define an empty -drawRect for fooView , then there will be no animation - the background is immediately replaced with blue.
It didnβt matter if using [UIView animateWithDuration: ...] or [FooView animateWithDuration: ...] - this is not an animation.
If inside is -drawRect , I call [super drawRect:rect]; , then itβs the same thing: no animation.
If I change drawRect to drawRect2 , or if I delete the entire method, the animation will work.
(and you might need -drawRect , for example, what if we need to draw a circle in a custom FooView?)
Why? Also, to give a decision on how to make it work even with -drawRect , please explain what happens, which made it inanimate?