How to change the segue transition style from bottom to top instead of right to left in navigation controllers? - swift

I am trying to change the transition animation in navigation controller to load a new UIView controller from bottom to top, using Segue. I believe it will not be too hard to implement but may be I am not able to understand it.
My first attempt was to use Hero library but it does not work for some reason.
The answers found so far were only in Objective-C

You can try this solution to present your new controller modally.
let storyboard = UIStoryboard(name: "Storyboard Name", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "Controller Name
")
self.present(controller, animated: true, completion: nil)

Related

Height of view as a modal popup - Swift

In the app that I am creating with XCode I created a view that opens as a modal popup. I used this code:
#IBAction func open_view(_ sender: Any) {
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let VC_test_object = storyBoard.instantiateViewController(withIdentifier: "VC_Test")
VC_test_object.modalPresentationStyle = .popover;
self.present(VC_test_object, animated: true, completion: nil)
}
VC_Test is the ViewController in Storyboard. This is the result:
However, I would like to manage the height of the view to create a sort of menu.
As in this example screenshot (from the Documents app):
I can't understand how to do it.
Could you tell me how to manage the height of the popup?
Thanks for your help.
For a code-your-self version this SO link and the answers below it is what you need: Present modal view controller in half size parent controller
However, I would rather use this third party library : Presentr

View on View controllers are all square shaped on Xcode 11, how?

I have tried to change it's size manually (by dragging) and still not working.
You can set its Content size to whatever you want.
On iOS 13 a "Modal" segue will show the presenting controller that way by default.
If you want the view controller to occupy the whole screen, set "Full Screen" on the "presentation" setting of any segue entering that controller.
Segue Settings
If your view presents programmatically (not via storyBoard), have this in mind:
From XCode 11 and up, when you build for iPad you have to add "modalPresentationStyle = .fullScreen" to get full screen views, not square ones. As follows:
let vc = UIViewController()
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)
If you want transparency on the new viewController, you can write ".overFullScreen", as follows:
let vc = UIViewController()
vc.modalPresentationStyle = .overFullScreen
self.present(vc, animated: true, completion: nil)

Cant dismiss view controller after present it

After presenting a Tab bar controller, I can't dismiss tab bar controller.
I also can't even tap my button after I reinstall without delete the app. Need to uninstall and reinstall the app then I am able to tap the button
I already tried some other way of dismiss the tab bar controller but still unable to dismiss the controller.
This is my current way to present controller after login
let storyboard = UIStoryboard.init(name: "Main", bundle: Bundle.main)
let loginVC = storyboard.instantiateViewController(withIdentifier: "Home")
self.present(loginVC, animated: true, completion: nil)
This is my current way to dismiss controller
#IBAction func btnLogout_TouchUpInside(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
This is my root view
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
if defaults.bool(forKey: "isLoggedIn") {
// Show Home screen
window?.rootViewController = storyboard.instantiateViewController(withIdentifier: "Home")
} else {
// Show Login screen
window?.rootViewController = storyboard.instantiateViewController(withIdentifier: "Login")
}
window?.makeKeyAndVisible()
try to dismiss all presented controller it may work for you
DispatchQueue.main.async {
self.view.window!.rootViewController?.dismiss(animated: true, completion: {
print("All controller dismissed successfully..")
})
}
Try This
self.presentingViewController?.dismiss(animated: true, completion: nil)
Hmm. Your update helps although I'm still not sure what's happening. My guess is that you are setting login as root, then presenting home. But I'm not sure where or what you are trying to dismiss. If it's on the login then there is nothing to dismiss as it's the root view controller.
My suggestion would be to reconfigure the storyboard. Because you are manually presenting the view controllers I'm going to assume that the storyboard doesn't contain any segues between the controllers. I'd suggest adding the segues and using them.
I'd set the home view controller as the initial view controller and set the Main storyboard as the storyboard to load in the apps settings. Then all the code to load the storyboard and set the root view controller can be removed.
Next I'd make a manual modal segue from the home view controller to the login view controller. Then in the viewDidAppear of the home view controller I'd add the code to decide if a login was needed and to them perform the login segue.
Then in the login view controller you can do a dismiss and it will remove the model login view.
This is but one of many ways to do this, but it's pretty much the simplest to get you going. You don't need any code to load or set root view controllers or anything else. It just lets the storyboard do the work for you.

modalPresentationStyle .overCurrentContext causing issues with remote button presses on presented view controller

I am having an issue with using the .overCurrentContext modalPresentationStyle on a tvOS view controller:
let vc = UIStoryboard(name: "", bundle: Bundle.main).instantiateInitialViewController() //representative of actually presented VC
vc.modalPresentationStyle = .overCurrentContext
present(vc, animated: true, completion: nil)
On the presented view controller, pressing the menu button ceases to return to the presenting view controller. This also occurs when setting it to .overFullScreen and .blurOverFullScreen. However, I am having no such problem when setting it to .currentContext or .fullScreen. Is there anything particular that needs to be used when using certain UIModalPresentationStyle's?
let vc = UIStoryboard(name: "", bundle: Bundle.main).instantiateInitialViewController() //representative of actually presented VC
vc.modalPresentationStyle = .overCurrentContext
self.definesPresentationContext = true //*** adding this line should solve your issue ***
self.present(vc, animated: true, completion: nil)
So what's going on here? The definesPresentationContext property was added in iOS 8, and the documentation states the following:
When a view controller is presented, iOS starts with the presenting view controller and asks it if it wants to provide the presentation context. If the presenting view controller does not provide a context, then iOS asks the presenting view controller's parent view controller. iOS searches up through the view controller hierarchy until a view controller provides a presentation context. If no view controller offers to provide a context, the window's root view controller provides the presentation context.
If a view controller returns YES, then it provides a presentation context. The portion of the window covered by the view controller's view determines the size of the presented view controller's view. The default value for this property is NO.
By setting definesPresentationContext to YES you ensure that the controller to be presented is presented within the bounds of the original view controller.

I want to move to another view controller without using navigation controller, segue,storyboard and animation. Anyone can help me?

I want to move to another view controller without using navigation controller, segue, storyboard and animation
You can use presentViewController like this
let controller = self.storyboard?.instantiateViewControllerWithIdentifier("YOUR_VIEWCONTROLLER_ID")
self.presentViewController(controller!, animated: false, completion: nil)