我想用 Core Animation 自定义推送和弹出动画!例如,我在 pushViewController 中编写了一些代码,如下所示:
{
//save currrent view's snapshot`
m_curLayer = [self _ConstructLayerByView:self.view];
[super pushViewController:viewController animated:NO];
//save the next view's snapshot
m_nextLayer = [self _ConstructLayerByView:self.view];
//add these two new layers to self.view.layer, and add customized animations to them.
[self _PushAnimation];
}
动画效果符合我的预期,但性能很差。经过一些分析,我发现 renderInContext 很慢。我的快照功能是:
+ (id)CaptureView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.frame.size, YES, [UIScreen mainScreen].scale);
CGContextRef contenxt = UIGraphicsGetCurrentContext();
[view.layer renderInContext:contenxt];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return (id) [newImage CGImage];
}
所以想问问有没有办法优化renderInContext,或者有更好的自定义动画的方法?