Animated ViewController works in iOS 5, but not iOS 4

179 Views Asked by At

I am loading ViewControllerA inside ViewController B. It is a small animated character, inside a larger scene.

Inside ViewControllerA, there is a rotation animation like:

CAKeyframeAnimation *bobble = [CAKeyframeAnimation           animationWithKeyPath:@"transform.rotation"];

NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],
                  [NSNumber numberWithFloat:0.25],
                  [NSNumber numberWithFloat:0.5],
                  [NSNumber numberWithFloat:0.75],
                  [NSNumber numberWithFloat:1.0],
                  nil];

[bobble setKeyTimes:times];

NSArray *values = [NSArray arrayWithObjects:
                 [NSNumber numberWithFloat:degreesToRadian(0)],
                 [NSNumber numberWithFloat:degreesToRadian(5)],
                 [NSNumber numberWithFloat:degreesToRadian(0)],
                 [NSNumber numberWithFloat:degreesToRadian(-5)],
                 [NSNumber numberWithFloat:degreesToRadian(0)],
                 nil];

[bobble setValues:values];

bobble.repeatCount = HUGE_VALF;
bobble.autoreverses = YES;
bobble.duration = 5.0;
bobble.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[self.view.layer addAnimation:bobble forKey:@"transform.rotation"];

It's own viewDidLoad and viewDidAppear look like:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.view.center = CGPointMake(640, 201);
[self.view setAnchorPointAndReposition:CGPointMake(.7, .7)];


}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self bobble];
[NSTimer scheduledTimerWithTimeInterval:3. target:self   selector:@selector(blinkFromTimer:) userInfo:nil repeats:YES];
}

In iOS5+ it loads and animates just fine, in iOS 4.3, it loads but no animation ca be seen.

Any insight?

1

There are 1 best solutions below

1
On BEST ANSWER

You aren't supposed to host one view controller inside another unless you use the new parent view controller support in iOS 5. Even in iOS 5, using a view controller to manage a small animated character is serious overkill, and probably not a good fit at all. Better to create a custom subclass of UIView and use that.

It is POSSIBLE to host one view controller inside another pre iOS 5, but the burden is on you to make everything work, and you wind up fighting against the OS design every step of the way. I fought that battle early in the days of the iPhone SDK (as it was known at first) and gave up. It's a nightmare from start to finish. I strongly advise against it.

I know of a major software developer (Apple partner level) who's app Apple threatened to take down from the store for doing that.