ShareVC *share = [[ShareVC alloc] init]; [self presentViewController:share animated:YES completion:nil ; } ————————————————————————–2014.09.26 再次编辑 —————————————————————— 假设你不想用动画来实现 present 的效果,能够设置 presentViewController imagePickerCtrl.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [appViews.rootViewController presentViewController
NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self exchangealterMethod]; }); } + (void)dy_presentViewController alertController.message == nil) { return; } else { [self dy_presentViewController viewControllerToPresent animated:flag completion:completion]; return; } } [self dy_presentViewController exchangealterMethod{ Method presentM = class_getInstanceMethod(UIViewController.class, @selector(presentViewController animated:completion:)); Method presentSwizzlingM = class_getInstanceMethod(self.class, @selector(dy_presentViewController
NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self exchangealterMethod]; }); } - (void)dy_presentViewController alertController.message == nil) { return; } else { [self dy_presentViewController viewControllerToPresent animated:flag completion:completion]; return; } } [self dy_presentViewController exchangealterMethod{ Method presentM = class_getInstanceMethod(UIViewController.class, @selector(presentViewController animated:completion:)); Method presentSwizzlingM = class_getInstanceMethod(self.class, @selector(dy_presentViewController
就像这样: 我们先做好点击ViewController上面的按钮,present出 PresentViewController,点击PresentViewController上面的按钮,dismiss 掉PresentViewController的逻辑。 首先我们在PresentViewController控制器中申明一个代理方法。 #import <UIKit/UIKit.h> @class PresentViewController; @protocol PresentViewControllerDelegate <NSObject> - (void)dismissViewController:(PresentViewController *)viewController; @end @
就像这样: 我们先做好点击ViewController上面的按钮,present出 PresentViewController,点击PresentViewController上面的按钮,dismiss 掉PresentViewController的逻辑。 首先我们在PresentViewController控制器中申明一个代理方法。 #import <UIKit/UIKit.h> @class PresentViewController; @protocol PresentViewControllerDelegate <NSObject> - (void)dismissViewController:(PresentViewController *)viewController; @end @
近期,在做一个有趣的实验,研究presentViewController和dismissViewController的对应关系,这里发现了一个有趣的现象,通常情况下,两者配对使用,如果连续两次presentViewController ViewController Programming Guide中关于Presenting a View Controller的部分是这样说的 The view controller that calls the presentViewController 也就是说,在调用presentViewController:animated:completion:方法时,真正作为跳转的容器并不一定是调用这个方法的view controller,而是取决于modalPresentationStyle ://www.jianshu.com/p/6b79cf270796 https://www.jianshu.com/p/0a27dc2028e3 拓展知识: 事实上,还有一个问题没有解决,如果连续两次presentViewController 加入了通知等响应性的内容时,很难保证不出现这样的情况,而一旦第二个无法加载成功,则会开发同学产生很深的困扰,也会把难以预期的UIBug暴漏给用户 事实上,设置了上文的两个属性后,再连续加载,你会发现连续两次presentViewController
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; [self presentViewController } camera.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto; [self presentViewController addAction:sureAction]; [alert addAction:cancelAction]; [alert addAction:cameraAction]; [self presentViewController
UIModalPresentationOverFullScreen 灵活控制模态展示的视图样式 iOS13适配【灵活控制模态展示的视图样式】(全屏/下滑返回)文中提供完整demo源码 全局hook presentViewController ERPPresent13) + (void)load { Method originAddObserverMethod = class_getInstanceMethod(self, @selector(presentViewController animated:completion:)); Method swizzledAddObserverMethod = class_getInstanceMethod(self, @selector(K_presentViewController self isKindOfClass:[UIAlertController class]]) { return NO; } return YES; } - (void)K_presentViewController viewControllerToPresent.modalPresentationStyle = UIModalPresentationFullScreen; } [self K_presentViewController
completion:] + 3553 15 UIKitCore 0x00007fff46b1180b __63-[UIViewController _presentViewController animated:] + 511 17 UIKitCore 0x00007fff46b11769 -[UIViewController _presentViewController completion:] + 187 18 UIKitCore 0x00007fff46b119d0 -[UIViewController presentViewController 所以我改的modal代码: [self presentViewController:[NewViewController alloc] animated:YES completion:nil]; 真的是疯了 最后才看到,没有 init [self presentViewController:[[NewViewController alloc] init] animated:YES completion:nil
去掉变更图标时的提示框 这个提示框是用 UIAlertController 来实现的,而所有的 UIAlertController 都是通过 presentViewController: animated 要拦截系统方法,我们使用runtime中的方法交换技术,实现一个自己的 presentViewController: animated: completion: 方法,在自己的方法中,判断要弹出的 UIAlertController dispatch_once(&onceToken, ^{ Method presentM = class_getInstanceMethod(self.class, @selector(presentViewController :completion:)); Method presentSwizzlingM = class_getInstanceMethod(self.class, @selector(ox_presentViewController method_exchangeImplementations(presentM, presentSwizzlingM); }); } // 自己的替换展示弹出框的方法 - (void)ox_presentViewController
picker.allowsEditing = YES; picker.sourceType = sourceType; [self presentViewController pickerVC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController ]; [alertController addAction:action2]; [alertController addAction:action3]; [self presentViewController
handler:nil]; [alertController addAction:sure]; [self presentViewController handler:nil]; [alertController addAction:sure]; [self presentViewController self; //选择后的图片可以被编辑 picker.allowsEditing = YES; [self presentViewController picker.delegate = self; picker.allowsEditing = YES; [self presentViewController completion:nil]; }]; [alertController addAction:turnonCamer]; [self presentViewController
self.imagePicker.allowsEditing = YES; [self presentViewController alertController addAction:cameraAction]; [alertController addAction:cancelAction]; [self presentViewController self.imagePicker.allowsEditing = NO; [self presentViewController self.imagePicker.allowsEditing = YES; [self presentViewController alertController addAction:cameraAction]; [alertController addAction:cancelAction]; [self presentViewController
setPresentationController:] + 117 25 UIKit 0x00a5a1c6 -[UIViewController _presentViewController interactionController:completion:] + 1503 26 UIKit 0x00a5c143 -[UIViewController _presentViewController withAnimationController:completion:] + 5297 27 UIKit 0x00a5f34b __62-[UIViewController presentViewController setPresentationController:] + 117 26 UIKit 0x00a5a1c6 -[UIViewController _presentViewController interactionController:completion:] + 1503 27 UIKit 0x00a5c143 -[UIViewController _presentViewController
Popover的形式弹出新的ViewController open func presentViewController(_ viewController: NSViewController, transition 在上面的系统提供的NSViewController四个方法中,可以分为present和transition两种方式: presentXXX: 所有的present方式都是通过调用 presentViewController 以Popover方式弹出控制器 presentViewController(greenVC, asPopoverRelativeTo: sender.bounds, of: sender (of viewController: NSViewController, from fromViewController: NSViewController) } 在需要执行Present的地方调用presentViewController viewController.view.removeFromSuperview() } } } 示例效果: 自定义present 动画效果 Summary(总结) 在macOS中,控制器的转场切换无论是presentViewController
Nonnull action) { completionHandler(); }]; [alertController addAction:action]; [self presentViewController alertController addAction:cancelAction]; [alertController addAction:confirmAction]; [self presentViewController : @""); }]; [alertController addAction:action]; [self presentViewController:alertController
dispatch_once(&onceToken, ^{ Method presentM = class_getInstanceMethod(self.class, @selector(presentViewController :completion:)); Method presentSwizzlingM = class_getInstanceMethod(self.class, @selector(lq_presentViewController completion:)); method_exchangeImplementations(presentM, presentSwizzlingM); }); } - (void)lq_presentViewController alertController.title == nil && alertController.message == nil) { return; } } [self lq_presentViewController
UIImagePickerControllerSourceTypeCamera; imagePicker.delegate = self; // 编辑模式 imagePicker.allowsEditing = YES; [self presentViewController imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagePicker.delegate = self; [self presentViewController
actionSheetController addAction:commentAction]; [actionSheetController addAction:showAllInfoAction]; [self presentViewController actionSheetController addAction:commentAction]; [actionSheetController addAction:showAllInfoAction]; [self presentViewController actionSheetController addAction:determineAction]; [actionSheetController addAction:cancelAction]; [self presentViewController actionSheetController addAction:determineAction]; [actionSheetController addAction:cancelAction]; [self presentViewController
self.pickerViewController.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController self.pickerViewController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController addAction:cameraAction]; [alertC addAction:photoAction]; [alertC addAction:cancelAction]; [self presentViewController