Navigation Controller with Flip animation - ios

I've just started to learn to code in Swift and in the process of building a restaurant iOS app.
I basically have a table view of restaurants with a Map button on the top right, embedded in the nav. When you click on it, I like the view to flip to reveal a map.
How do I go about doing this?
The push segue seems to fixate on a default animation.

Take a look at UIView.transitionFromView method. First you will have to build your map view in code. Assuming you have that already you do following thing:
UIView.transitionFromView(self.view,
toView: yourMapView,
duration: someDuration,
options: UIViewAnimationOptions.TransitionFlipFromLeft,
completion: nil)
in your UITabBarItem action.

You can present the new view controller modally and set its modalTransitionStyle to . FlipHorizontal. For example:
let mapViewController = MapViewController()
mapViewController.modalTransitionStyle = .FlipHorizontal
self.presentViewController(newViewController, animated: true, completion: nil)

Related

Page views not correctly sized after segue

I recently updated my XCode to version 11.0. Ever since the update segues on an old project have been behaving weirdly. When I segue modally to a new page the page does not fill the entire screen and seemingly hovers instead.
Here is a picture of the view:
https://imgur.com/dAxEr4q
I would like for the pages to take up the full length of the device screen as they did prior to the upgrade.
Thanks in advance for any assistance.
This has to do with the new default modal presentation style in iOS 13.
To set the prior behavior, you need to change the presentation style to full screen.
You can do this both in storyboard by editing your segue's Presentation attribute and setting it from Automatic to Full Screen:
Alternatively, if you are presenting your View Controller programmatically, you can set your View Controllers modalPresentationStyle before presenting it, like so:
let detailController = /* your View Controller */
detailController.modalPresentationStyle = .overFullScreen
present(detailController, animated: true, completion: nil)
So the solution turned out to be more obvious than I realized. If you click on the segue symbol on the storyboard some options are displayed in the side bar.
Selecting presentation -> full screen from the drop down fixed my issue.
Adding a screenshot for clarity: https://imgur.com/BRCbx5k
Hope this helps anyone else having segue problems :)
You can programmatically present the controller like in below code :
let vc = secondStoryBoard.instantiateViewController(withIdentifier: "SearchNavVC")
vc.modalPresentationStyle = .fullScreen
vc.modalTransitionStyle = .crossDissolve
self.present(vc, animated: true, completion: nil)

How is this settings popup created? [duplicate]

This question already has answers here:
Present a popover from an arbitrary anchor point in Swift
(3 answers)
Closed 4 years ago.
I really like the way the settings are shown on the Books app and am trying to figure out how replicated it.
Screenshot of Books app with settings shown
Is this an .actionsheet that is somehow moved to show up under the Settings image or a container view that shows up on tap or something else? I'm still at level noob with a basic app and would like to implement this.
It is iOS default presentation style for controllers. It's called UIPopOverPresentationController. Here's a good article on presentation controllers. After that you might want to create two to three cells for your options in a UITableView and add that as controller for the popover from your storyboard.
You can also change the popover arrow pointing location and direction which you might need when you want to support your app for iPad as well. :)
#IBAction func actionWasTapped(sender: UIBarButtonItem) {
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "PopOverVC")
vc.modalPresentationStyle = .popover
let popover: UIPopoverPresentationController = vc.popoverPresentationController!
popover.barButtonItem = sender
present(vc, animated: true, completion: nil)
}
This can done with a-lot of way , you can just create by
UIView work as background with custom subview (PopOverMenu) done with UIBezierPath to draw this arrow with corner radius view
upon this pop over you can create MultiSection tableview or collection View or any
Background is add as SubView to UIApplication.sharedApplication().keyWindow?.addSubview(background)
Background have tab gesture to dismiss when tab on background
some closure to bring back data that user select it

Is it possible to prepare/reset a scene before it is shown / before viewDidAppear / viewDidLoad?

I am having a viewController with a couple of animated buttons, when the user presses a button the background is blurred (animation) and a menu to choose a couple of things (which all go to a new viewController) is presented.
So basically there is a scene, the user opens the menu, the scene is blurred except for the menu and the user presses a button and another viewController is shown programmatically with a crossDissolve. This is how I show the new controller:
let storyboard = UIStoryboard.init(name: "Timer", bundle: nil)
let vc = storyboard.instantiateInitialViewController()!
vc.modalTransitionStyle = .crossDissolve
present(vc, animated: true, completion: nil)
So far so good, but I am not able to reset the original scene (basically to just remove the blur and reset the animated buttons). I have a function in it called setupScene() which prepares everything for the app start (some buttons are hidden, the blur has an alpha of 0, etc....).
I just dismiss the new viewController like this:
dismiss(animated: true, completion: nil)
And than the original scene with it's last state (blurred etc.) is shown again.
So when the new viewController is presented I would like to reset everything in the original viewController in the background, so that when the new viewController is dismissed the old scene is already reset, but this doesn't work. I tried to move the setupScene() function in viewDidAppear, but either in viewDidAppear or viewDidLoad first the new viewController is dismissed showing the original viewController in it's last state with the blur again and then the setupScene() runs to reset everything (which obviously works fine).
Is there a way to reset everything in the background while the new viewController is shown or while the crossDissolve is running?
This sounds like a good case for viewWillAppear. This is a lifecycle method that is called when the visibility of a view controller's views change. viewDidLoad is only called once.
There are several solutions to this, depending on how fancy you want to get.
Based on what you describe I think the first thing to try is to take advantage of that completion parameter in dismiss(animated:completion:)
It's a callback to your code once the dismiss is completed. This will allow you to reverse your animation.
The callback takes no parameters.
So, if your setupScene() method does what it says,
dismiss(animated: true, completion: {
setupScene()
})
should do it.

Present Modal View in Detail View in UISplitViewController

I want to make a behavior like contacts app in iPad with landscape mode.
I'm expecting that a Modal shows in a Detail view when I click upper right add button.
but now if I click upper right add button, the Modal shows in all screen.
what method should I use? showDetailViewController? or presentViewController? I don’t know how to show Modal in only Detail View.
Firstly you need to set detail view controller's property definesPresentationContext = true. So now it defines presentation context. By default view controllers doesn't pay attention to the current context when they are presented therefore you must do viewController.modalPresentationStyle = .CurrentContext
That's how complete method looks like
func adaptivePresentViewController(viewController: UIViewController) {
let detailVC = splitViewController!.viewControllers[1]
detailVC.definesPresentationContext = true
viewController.modalPresentationStyle = .CurrentContext
detailVC.presentViewController(viewController, animated: true, completion: nil)
}

Proper way to present UIActivityViewController inside UINavigationController inside popup

Suppose I have a UINavigationController inside a UIPopup. From there, I try to present a UIActivityViewController, by pushing it into the view controller.
if let navigationController = self.navigationController{
navigationController.pushViewController(activityViewController, animated: true)
}else{
self.presentViewController(activityViewController, animated: true, completion: nil)
}
The code executes without errors, however:
The displayed UIActivityViewController is corrupted and some text is not visible. (See image)
While pushing the view, part of the screen flashes when the popup resizes to accommodate the view (the popover is in the right side of the screen, and a ~150px vertical strip becomes brighter on the left)
As far as I know, I do not break Apple's Human Interface Guidelines by presenting the view this way. If so, what can be done so the view displays flawlessly?

Resources