1. 程式人生 > >iOS自定義Modal

iOS自定義Modal

通過‘小麵包’分析系統自帶Modal可以得出:

Modal出來控制器的View檢視是新增到UIWindow上

因此若自定義Modal效果控制器,只需把自定義modal控制器的view新增到window上,同時把當前的view移除,然後添加個相應動畫模擬完成。

UIModalViewController *modalVc = [[UIModalViewController alloc] init];
self.modalVc = modalVc;//必須強引用著,不能被銷燬

UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
[keyWindow addSubview: modalVc.view];

[UIView animateWithDuration:0.25 animations:^{
    modalVc.view.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
    [self.view removeFromSuperview];
}];