I want to be able to present a viewController with crossDissolve but dismiss it with the traditional top to bottom dismissal.
Is there a way to change the modalTransitionStyle once the viewController has opened?
Here is how I am currently presenting
I want to be able to present a viewController with crossDissolve but dismiss it with the traditional top to bottom dismissal.
Is there a way to change the modalTransitionStyle once the viewController has opened?
Here is how I am currently presenting
let layout = UICollectionViewFlowLayout()
let userSearchController = UserSearchController(collectionViewLayout: layout)
userSearchController.modalTransitionStyle = .crossDissolve
currentController?.present(userSearchController, animated: true, completion: nil)
Using #Jason's comment I did the following
userSearchController.modalTransitionStyle = .crossDissolve
currentController?.present(userSearchController, animated: true, completion: {
userSearchController.modalTransitionStyle = .coverVertical
})
and it works perfectly
Related
I am trying present a navigation controller with UITabBarController, I am confused why UITabBarController's viewDidAppear is not called again after the navigation controller dismissed. How can I manage to do that?
Change presentation style to currentContext. For example:
let controller = ViewController()
controller.modalPresentationStyle = .currentContext //<-- Add this line
self.present(controller, animated: true, completion: nil)
I have a UIViewcontroller that presents a popUpView with two buttons, cancel and continue respectively.. but the problem is that when I press the continue button, UINavigationController is not pushing to the next UIViewcontroller.. .
-- onNextButtonTapped:
#IBAction func onOkayButtonClicked(_ sender: UIButton) {
self.dismiss(animated: true, completion: {
let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "nextVC") as! NextViewController
// let nextVCNav = UINavigationController(rootViewController: nextVC)
//self.navigationController?.pushViewController(nextVCNav, animated: true)
self.navigationController?.pushViewController(nextVC, animated: true)
})
}
Did miss something?
This seems like a controller chain issue. As from what I understand you must have presented the popup modally and by doing that you have moved out of the UINavigationController stack. So pushing a view from popupview controller is not an option. You can:
Create a protocol, (or block implementation) that inform viewcontroller which presented popup, that particular button was clicked (something similar to UIAlertController)
Make a popup as a view inside view controller and show and hide that with animation. That was you can add the action of the button of this popup to your view controller.
I think the UINavigationController is not in hierarchy.
Try this
let nav = UINavigationController(rootViewController: self)
UIApplication.shared.keyWindow?.rootViewController = nav
nav.pushViewController(nextVC, animated: true)
I have a weird behavior when presenting UIViewControllers modally in iOS 13. The new presentation style that I've seen all across iOS 13 looks like this:
The presenting view controller appears behind the presented view controller. It is also shifted down to mimic a "stack"
Meanwhile, when presenting view controllers through my app, I keep getting this effect:
The presenting view controller doesn't move at all when presenting a new view controller
I use this code to present this view controller:
let controller = storyboard?.instantiateViewController(withIdentifier: "tutorial") as! TutorialController
controller.modalPresentationStyle = .pageSheet
controller.modalTransitionStyle = .coverVertical
present(controller, animated: true, completion: nil)
Here is my question:
I'm wondering why this is happening and if there is a way to present view controllers in the normal iOS 13 style (with the presenting view controller moving back).
Thanks in advance!
Turns out the problem was my view controller hierarchy. I was able to fix it by making the presenting view controller the root view controller of my app. First I set the background controller as the root view controller by calling
window.rootViewController = self
and then using my previous code
let controller = storyboard?.instantiateViewController(withIdentifier: "tutorial") as! TutorialController
controller.modalPresentationStyle = .pageSheet
controller.modalTransitionStyle = .coverVertical
present(controller, animated: true, completion: nil)
I presented the view controller. Thanks to everyone who tried to help!
I think the issue can be resolved by using vc.modalPresentationStyle = .fullScreen if there is not UINavigationController , otherwise you can use these codes as follows:
let navigationController = UINavigationController(rootViewController: vc)
navigationController.modalPresentationStyle = .fullScreen
present(vc, animated: true)
because With iOS 13 this is a new feature that Apple has changed the default presentation style of View Controllers to a modal sheet from fullscreen in iOS 12
Programmatically:
let vc = UIViewController()
vc.modalPresentationStyle = .fullScreen //or .overFullScreen for transparency
self.present(vc, animated: true, completion: nil)
From storyboard:
That's it. No need to play with root controller or window at all.
For reference, visit this article.
iOS13: Let's say you have 3 view controllers: FirstVC, SecondVC, ThirdVC
FirstVC presents SecondVC with the below code:
let secondVC = SecondVC()
secondVC.modalPresentationStyle = .fullScreen
firstVC.present(secondVC, animated: true, completion: nil)
SecondVC presents ThirdVC with the below code:
let thirdVC = ThirdVC()
secondVC.present(thirdVC, animated: true, completion: nil)
Changing secondVC's modalPresentationStyle to .currentContext solves the problem.
We can change it in the Inspector Tool Bar. To Achieve it: head over to the fifth section of Inspector Tollbar then change the Presentation field to Full Screen.
This should be the only property you need to set
presentedViewController.modalPresentationStyle = .automatic
Detailed in
https://developer.apple.com/videos/play/wwdc2019/224/
I have already presented a controller on the screen and now click on the home button. Then I need to present another controller on that after tapping on notification using deeplink.
When app comes to foreground, new controller is nor presented and previous controller is also dismissed.
Getting below Warning as well:-
Attempt to present <NewController> on <PreviousController> whose view is not in the window hierarchy!
I am using below code to present.
controller.transitioningDelegate = myDelegateForTransition
controller.modalPresentationStyle = .custom
controller.modalPresentationCapturesStatusBarAppearance = true
viewControllerFromPresent.present(controller, animated: true, completion: {
completionHandler?()
})
I resolved it by changing controller.modalPresentationStyle from custom to overCurrentContext.
controller.transitioningDelegate = myDelegateForTransition
controller.modalPresentationStyle = .overCurrentContext
controller.modalPresentationCapturesStatusBarAppearance = true
viewControllerFromPresent.present(controller, animated: true, completion: {
completionHandler?()
})
I have a UIViewController that presents another ViewController like that:
let blurryVC = BlurryViewController(names: ["name1, "name2", "name3"])
let navigationC = UINavigationController(rootViewController: blurryVC)
self.modalPresentationStyle = .overFullScreen
self.present(navigationC, animated: true, completion: nil)
on BlurryViewController I have a UIVisualEffectView, when I present this VC the blur works for around 1 second and then it become black. I think something happening the the view of the VC behind.
How can I prevent it from being black when I present it?
Thank you!