参考: 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错误反而用不了
相关推荐
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...
paper写作入门的经典教材!我觉得作者讲的方法,比如第一章的表格法分析native speaker的语言习惯,都是很有操作性的。第二部分讲会议presenting的准备,好像没几本书讲这个的吧?我强力推荐此书!
• 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, ...
1.1 Creating a Simple iOS App in Xcode 2 1.2 Understanding Interface Builder 7 1.3 Compiling iOS Apps 13 1.4 Running iOS Apps on the Simulator 15 1.5 Running iOS Apps on iOS Devices 17 1.6 Packaging ...
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...
Truly outstanding iOS games go beyond addictive gameplay and beautiful graphics by presenting players with interfaces that are thoughtfully designed and carefully implemented. Receive practical advice...
// UIView.animateWithDuration(transitionDuration(transitionContext), animations: { () -> Void in // var trans = CGAffineTransformMake(0.1, CGFloat(M_PI_2), CGFloat(M_PI_2), 0.1, -width/2, height/2) //...
Picture Map is presenting your iPhone camera roll content in a new and exciting way!
演示制胜——讲故事的艺术 Presenting to Win 口才制胜:讲故事的艺术 演示制胜——讲故事的艺术 Presenting to Win 口才制胜:讲故事的艺术 对创业路演,总结工作,报告都非常有用
Presenting Java Beans
Presenting Java Beans (Sams).pdf
You’ll also review presenting data through consumer applications in widely adopted technologies such as Angular, Ember, React, and Vue.js. Featuring a foreword by Drupal founder and project lead ...
Congenital Dyserythropoietic Anaemia (Type II) Presenting with Haemosiderosis
The number of edges used in the tests was held in 500 pieces at all times. The study also marked out how the performance of the computers or the different browsers affected the results. The final ...
本书由FT金融时报出版发行,作者号称世界第一的Presentation顾问,随便翻几页你就会感觉到他不同一般的说服力。 一开始从原理入手,告诉读者Presentation的重要性,以及要想做好Presentation的基本原理。...
Java Reflection in Action is unique in presenting a clear account of all the cool things you can do with reflection, and at the same time pro- viding the sound conceptual basis that developers need to...
This textbook introduces sparse and redundant representations with a focus on applications in signal and image processing. The theoretical and numerical foundations are tackled before the applications...