参考: https://stackoverflow.com/questions/56435510/presenting-modal-in-ios-13-fullscreen
There are multiple ways to do that, and I think each one could fit for one project but not another, so I thought I'll keep them here maybe someone else will run to a different case.
1- Override present
If you have a BaseViewController
you can override the present(_ viewControllerToPresent: animated flag: completion:)
method.
classBaseViewController:UIViewController{// ....override func present(_ viewControllerToPresent:UIViewController,
animated flag:Bool,
completion:(()->Void)?=nil){
viewControllerToPresent.modalPresentationStyle =.fullScreen
super.present(viewControllerToPresent, animated: flag, completion: completion)}// ....}
Using this way you don't need to do any change on any present
call, as we just overrode the present
method.
2- An extension:
extension UIViewController{
func presentInFullScreen(_ viewController:UIViewController,
animated:Bool,
completion:(()->Void)?=nil){
viewController.modalPresentationStyle =.fullScreen
present(viewController, animated: animated, completion: completion)}}
Usage:
presentInFullScreen(viewController, animated:true)
3- For one UIViewController
let viewController =UIViewController()
viewController.modalPresentationStyle =.fullScreen
present(viewController, animated:true, completion:nil)
4- From Storyboard
Select a segue and set the presentation to FullScreen
.
5- Swizzling
extension UIViewController{static func swizzlePresent(){let orginalSelector =#selector(present(_: animated: completion:))let swizzledSelector =#selector(swizzledPresent)
guard let orginalMethod = class_getInstanceMethod(self, orginalSelector),let swizzledMethod = class_getInstanceMethod(self, swizzledSelector)else{return}let didAddMethod = class_addMethod(self,
orginalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod))if didAddMethod {
class_replaceMethod(self,
swizzledSelector,
method_getImplementation(orginalMethod),
method_getTypeEncoding(orginalMethod))}else{
method_exchangeImplementations(orginalMethod, swizzledMethod)}}@objcprivate func swizzledPresent(_ viewControllerToPresent:UIViewController,
animated flag:Bool,
completion:(()->Void)?=nil){if#available(iOS 13.0, *) {if viewControllerToPresent.modalPresentationStyle ==.automatic {
viewControllerToPresent.modalPresentationStyle =.fullScreen
}}
swizzledPresent(viewControllerToPresent, animated: flag, completion: completion)}}
Usage:
In your AppDelegate
inside application(_ application: didFinishLaunchingWithOptions)
add this line:
UIViewController.swizzlePresent()
共有5种方法,第一第二种都不错,第三种比较常见,如果很多地方用到present就每一个都需要设置一下,不太优雅.
第四种是要有storyboard的segue,如果代码跳转用不上.
第五种其实是最好的很优雅,而且基本对原代码没有修改.但是如果原代码是OC的话,会有问题,提示selector错误反而用不了
相关推荐
在本文中,我们将深入探讨如何在ModalView与呈现者(Presenting View Controller)之间传递数据,特别是如何利用委托对象(Delegate)来实现这一功能。我们将基于MVC(Model-View-Controller)设计模式来讨论这个...
### 《Writing and Presenting in English:The Rosetta Stone of Science》相关知识点解析 #### 一、书籍概览 《Writing and Presenting in English:The Rosetta Stone of Science》是一本旨在帮助科研工作者...
• Chapter 5, Presenting Data in Table Views, on page 79, • Chapter 6, Waiting for Things to Happen with Closures, on pa • Chapter 7, Doing Two Things at Once with Closures, on page • Chapter 8, ...
在iOS开发中,Action Sheet是一种常见的用户界面元素,它用于提供多个操作选项供用户选择,通常在用户需要执行重要或有潜在危险的操作时出现。在这个“ios应用源码之分享action sheet 2018127”的项目中,我们可以...
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { return ...
6. **考虑设备旋转限制**:iOS 13及以上版本,你可能还需要在Info.plist中添加` UISupportedInterfaceOrientations~ipad `和` UISupportedInterfaceOrientations `键,分别指定iPad和iPhone的屏幕方向支持。...
在iOS开发中,有时我们希望实现一种特殊的效果,比如在presenting一个新的视图控制器时,不仅保持原有的背景可见,还能给用户带来半透明或者毛玻璃(Blur Effect)的视觉体验。在这种情况下,我们需要创建一个透明的...
6. **`UIViewControllerTransitioningDelegate`**:如果你的控制器需要自定义转场,可以设置此委托,然后实现`animationController(forPresented:presenting:source:)`和`animationController(forDismissed:)`方法,...
5. **呈现页面(Presenting ViewController)** 在上述描述中,我们提到了`presentModalViewController`。在Swift中,对应的方法是`present(_:animated:completion:)`。调用此方法将呈现新的页面。确保在调用此方法...
通过实现`animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController)`和`animationController(forDismissed dismissed: UIViewController)`方法,你...
First, this approachable text covers the fundamentals of Swift by introducing you to iOS development in this language, and presenting best practices for setting up a development environment and using...
First, this approachable text covers the fundamentals of Swift by introducing you to iOS development in this language, and presenting best practices for setting up a development environment and using...
通过实现`animationController(forPresented:presenting:source:)`和`animationController(forDismissed:)`方法,可以指定呈现和消失时的动画控制器。同时,`interactionController(forDismissal:)`可以为用户交互式...
- **1.9 Presenting and Managing Viewswith UIView Controller** - **知识点**:UIViewController 用于管理视图,并负责呈现视图。 - **应用场景**:创建复杂的用户界面,控制视图之间的导航和过渡。 #### 小结...
- 动画实现:检查可能存在的自定义动画代码,这可能在`animateTransition:`或`animationController(forPresented:presenting:source:)`等方法中。 - 手势处理:找出处理滑动手势的代码,可能在手势识别器...
当用户点击图片时,触发手势识别器的事件,然后可以使用UIImageView的`zoomToRect:animated:`方法来放大图片,或者通过presenting一个全屏的UIImageView来显示大图。 总的来说,这个DEMO项目涵盖了UITableView的...
在iOS开发中,ViewController的转场切换效果是用户体验的重要组成部分,尤其在iOS7之后,苹果引入了一系列新API,使得开发者能够更加灵活、个性化地实现转场动画。本文将详细介绍这些新特性,帮助开发者掌握如何创建...
放大可能通过presenting一个新的ViewController,或者使用UIZoomView来实现。 对于图片的显示,可能采用了UIImageView的contentMode属性来控制图片如何适应其frame。例如,设置为UIViewContentModeScaleAspectFit...