IOS中如何模拟UINavigationController的Slide动画
在IOS中,UINavigationController在添加(push)与删除(pop)View的时候,会加入Slide的动画。有时候,在需要自己进行模拟这个动画的时候,会比较麻烦。
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
transition.fillMode = kCAFillModeBackwards;
transition.speed = 0.5f ;
transition.removedOnCompletion = YES;
[self.view.layer removeAllAnimations];
[self.view.layer addAnimation:transition forKey:nil];
UIGraphicsBeginImageContext(viewController.view.bounds.size);
CALayer *layer = viewController.view.layer;
[layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:0.35f];
[UIViewsetAnimationDelegate:self];
[UIViewsetAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];
imageView.origin = CGPointMake(imageView.origin.x-screenRect.size.width, imageView.origin.y) ;
maskImageView.origin = CGPointMake(maskImageView.origin.x-screenRect.size.width, maskImageView.origin.y);