presentModalViewController方法,present一个透明的viewController,带动画效果
//假设需要被present的控制器实例为controller,controller的背景色设置为clearColor
UIViewController * rootcontroller = self.view.window.rootViewController; rootcontroller.modalPresentationStyle = UIModalPresentationCurrentContext;//进入的动画失效
[rootcontroller presentViewController:controller animated:NO completion:^{ rootcontroller.modalPresentationStyle = UIModalPresentationFullScreen; }]; controller.view.transform = CGAffineTransformMakeTranslation(0, controller.view.frame.size.height); [UIView animateWithDuration:0.35 animations:^{ controller.view.transform = CGAffineTransformMakeTranslation(0, 0); }];
将其封装成Catrgory后,备用:
- (void) presentTransparentController:(UIViewController *)controller withDuration:(CGFloat) duration { controller.view.backgroundColor = [UIColor clearColor]; controller.view.transform = CGAffineTransformMakeTranslation(0, controller.view.frame.size.height); [UIView animateWithDuration:duration animations:^{ controller.view.transform = CGAffineTransformMakeTranslation(0, 0); }]; self.modalPresentationStyle = UIModalPresentationCurrentContext;//让进入的动画失效 [self presentViewController:controller animated:NO completion:^{ self.modalPresentationStyle = UIModalPresentationFullScreen; }]; }