এটি করার একাধিক উপায় রয়েছে এবং আমি মনে করি প্রত্যেকেই একটি প্রকল্পের জন্য ফিট করতে পারে তবে অন্যটির জন্য নয়, তাই আমি ভেবেছিলাম আমি এগুলি এখানে রাখব হয়তো অন্য কেউ অন্য কোনও ক্ষেত্রে চলে যাবে।
1- উপস্থিত ওভাররাইড
আপনার যদি একটি থাকে তবে BaseViewControllerআপনি present(_ viewControllerToPresent: animated flag: completion:)পদ্ধতিটি ওভাররাইড করতে পারেন ।
class BaseViewController: UIViewController {
// ....
override func present(_ viewControllerToPresent: UIViewController,
animated flag: Bool,
completion: (() -> Void)? = nil) {
viewControllerToPresent.modalPresentationStyle = .fullScreen
super.present(viewControllerToPresent, animated: flag, completion: completion)
}
// ....
}
এই পদ্ধতিটি ব্যবহার করে আপনাকে কোনও presentকলটিতে কোনও পরিবর্তন করার দরকার নেই , যেমন আমরা কেবল presentপদ্ধতিটি ওভাররড করেছি ।
2- একটি এক্সটেনশন:
extension UIViewController {
func presentInFullScreen(_ viewController: UIViewController,
animated: Bool,
completion: (() -> Void)? = nil) {
viewController.modalPresentationStyle = .fullScreen
present(viewController, animated: animated, completion: completion)
}
}
ব্যবহার:
presentInFullScreen(viewController, animated: true)
3- একজন ইউআইভিউকন্ট্রোলারের জন্য
let viewController = UIViewController()
viewController.modalPresentationStyle = .fullScreen
present(viewController, animated: true, completion: nil)
4- স্টোরিবোর্ড থেকে
একটি সিগ নির্বাচন করুন এবং এতে উপস্থাপনাটি সেট করুন FullScreen।

5- সুইজলিং
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)
}
}
@objc
private 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)
}
}
ব্যবহার:
আপনার AppDelegateঅভ্যন্তরে application(_ application: didFinishLaunchingWithOptions)এই লাইনটি যুক্ত করুন:
UIViewController.swizzlePresent()
এইভাবে ব্যবহার করে আপনাকে কোনও বর্তমান কলটিতে কোনও পরিবর্তন করার দরকার নেই, কারণ আমরা রানটাইমটিতে বর্তমান পদ্ধতি প্রয়োগটি প্রতিস্থাপন করছি।
আপনি কি সুইজিং করছে তা জানতে হলে আপনি এই লিঙ্কটি দেখতে পারেন:
https://nshipster.com/swift-objc-runtime/
fullScreenবিকল্পটি ডিফল্টরূপে অবিচ্ছিন্ন UI 'তে অপরিবর্তিত রাখার জন্য হওয়া উচিত।