I am trying to do custom animations between view controllers and in the case below I am doing a mimicking of UINavigationController’s popViewController. However, it seems to lag a lot on iPhones and especially iPads and Time Profiler confirms it saying that all of the lag comes from the addSubview line.
Anyway, I connect nlView via Interface Builder and I use the code below:
[self.view.superview addSubview:nlView.view];
[nlView.view setFrame:CGRectMake(-kWidth, 20, kWidth, kHeight-20)];
[UIView animateWithDuration:2
animations:^{
[nlView.view setFrame:CGRectMake(0, 20, kWidth, kHeight-20)];
[self.view setFrame:CGRectMake(kWidth, 20, kWidth, kHeight-20)];
}
completion:^(BOOL finished){
[self.view removeFromSuperview];
}];
So, how could I minimize this lag to nothing at all? There are no leaks or anything like that but how could I just change my logic so that there is no lag when changing views?
Thanks!
If you want to animate the view’s position then instead of setting the frame, animate the view’s layer position like this:
[nlView.view.layer setPosition: newPosition]...of course you need to add QuartzCore to your project and import QuartzCore/QuartzCore.h