1.首先先創建一個windows:
@property (strong, nonatomic) UIWindow *alertWindow;
- (UIWindow *)alertWindow { if (!_alertWindow) { _alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *viewController = [[UIViewController alloc] init]; _alertWindow.rootViewController = viewController; } return _alertWindow;}
2.當我們要切換presentViewController至windows時,輸入如下:
[self.alertWindow makeKeyAndVisible]; [self.alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
3.至於要如何切回來原本的windows呢?只要在要切換的地方,輸入以下程式就可以了:
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate; [appDelegate.window makeKeyAndVisible];
沒有留言:
張貼留言