Randomly my app will not animate at all. My app has a sound bar that gets updated every 0.1 seconds with an animation. Usually when I start the app the animations will work all pretty and everything but then at a random point usually after I transition to another view controller (via setViewControllers
) it all of a sudden stops animationg. It's not just this animation but every animation in my app excluding setViewControllers
.
Here is my code where I call setViewControllers
:
- (void)goToController:(GeneralViewController *)vc animate:(BOOL)animated sub:(BOOL)sub{
if(animated){
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableArray *viewController = [NSMutableArray arrayWithArray:[delegate.navController viewControllers]];
if(viewController.count > 0){
viewController[0] = vc;
}else{
[viewController addObject:vc];
}
CATransition* transition = [CATransition animation];
transition.duration = 0.2;
transition.type = kCATransitionPush;
if(sub)
transition.subtype = kCATransitionFromRight;
else
transition.subtype = kCATransitionFromLeft;
[delegate.navController.view.layer addAnimation:transition forKey:kCATransition];
[delegate.navController setViewControllers:viewController animated:FALSE];
self.colorStyle = MusicPlusColorStyleLight;
}else{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableArray *viewController = [NSMutableArray arrayWithArray:[delegate.navController viewControllers]];
if(viewController.count > 0){
viewController[0] = vc;
}else{
[viewController addObject:vc];
}
[delegate.navController.view.layer removeAnimationForKey:kCATransition];
[delegate.navController setViewControllers:viewController animated:FALSE];
}
}
Here is the code I use to animate the sound bar:
[UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationCurveLinear | UIViewAnimationOptionBeginFromCurrentState
animations:^{
meterViewColor.frame = CGRectMake(0, (meterView.frameSizeHeight - (level*meterView.frameSizeHeight)), meterView.frameSizeWidth, (level*meterView.frameSizeHeight));
}
completion:nil];
I have checked and the code is running on the main thread. The CPU was on average around 10% and the Memory was 25 MB. So I am really baffled as to why it stops working sometimes. Has anyone else experienced this?
UPDATE: Sorry to say but the answer I posted was incorrect. It still isn't working. I have removed my answer and attached it bellow:
When creating the animation I added:
[transition setDelegate:self];
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.navController.view removeTransition];
}
- (void) removeTransition {
if (!CGAffineTransformIsIdentity(self.transform)) {
self.transform = CGAffineTransformIdentity;
}
}
finished
in the completion I'll bet it isNO
. Probably some bad math in the frame code. – Alex Reynolds