Following Apple's recommendations, I'm chaining UIView animations by putting subsequent calls to -animationWithDuration:animation:
in the completion:
block of another call to aanimateWithDuration:animation:completion:
, like so:
[UIView animateWithDuration:scaleDuration delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
// Scale the controllers' views down.
self.view.transform = CGAffineTransformScale(self.view.transform, 0.8, 0.8);
} completion:^(BOOL finished) {
// Transition to the new view and push on the new view controller.
[UIView transitionWithView:self.view duration:1 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionTransitionFlipFromLeft animations:^{
[self pushViewController:viewController animated:NO];
} completion:^(BOOL finished) {
[UIView animateWithDuration:scaleDuration delay:0 options:UIViewAnimationOptionCurveLinear animations:
^{
// Scale back to the original size.
self.view.transform = CGAffineTransformScale(self.view.transform, 1.25, 1.25);
} completion:nil];
}];
}];
The animations all execute the right order, but there is a tiny delay between them, especially before the -transitionWithView:duration:options:animations:completion:
call. How do I smooth out the transitions between animation steps?
self
in this context a navigation controller as your sendingpushViewController:
to it? and what is the intended animation, "flip" between views instead of sliding left/right as with a normal navigation controller? – RadianloadView
,viewDidLoad
,viewWillAppear
orviewWillLayoutSubviews
? if so check if they get called during the animation and make sure they don't do anything that takes time. – RadianviewWillAppear
, which in turn loads an NSFetchedResultsController and a bunch of views with images loaded from disk. That obviously might incur some overhead. I wonder if I can get it to do that before the animation starts… – Neddieinit
an then pass it as an argument when creating the view using it etc. – RadiangridView:cellForItemAtIndex:
, it definitely reduces the time, especially if I remove the image loading. There is still a slight pause, but greatly reduced. I just need to figure out how to get that stuff to load before the animation starts. – NeddielayoutSubviews
in AQGridView. I tried calling it before starting the animation, but that had no effect. Any ideas how to get it to load all the cells before starting the animation? – Neddieview
property manually it will cause the view controller to callloadView
(andviewDidLoad
etc). Try to do a dummy[self view]
call after the init somewhere, not sure if it's good or bad to do inside the view controller init. – Radian[viewController view]
call in the code per @danyowdee's answer, butlayoutSubviews
does not get called. :-( – Neddieview
is probably a bit of hack. Then I guess you need to load the image (or images?) before init (at app start?) and keep a reference is some global object that you can call. Is here a lot of images? – RadianviewDidLoad
that simply fetches each of the first 12 items and loads their images, but it doesn't seem to make much difference. Yes, it runs, but perhaps theNSManagedObject
returned byobjectAtIndexPath:indexPath:
aren't cached? :-( – Neddie