I am modally presenting a popover on top of a label similar to the popover you see when you do a long press on a message in a chat application like whatsapp or messages. The popover does not take over the entire view and the presenting view is visible in the background.
I have used a popoverPresentationController
However, I don't want the original presentingView (the tableView for the chat) to fade when the popover is active.
Is there anyway to control this?
You can use a presentViewController instead of a popoverPresentationController, using controller.modalPresentationStyle and controller.modalTransitionStyle to make it look as a Pop Over. I'm not sure if this is what you want, but this way you will have alpha = 1 in the parent view controller.
yourViewController.modalPresentationStyle = .overCurrentContext
self.present(yourViewController, animated: false, completion: nil)
Related
As I want to have more control over actions of when someone could press a button for going to another view controller, I tried to step away from the navigation controller system.
At the moment, as I'm still just a starter in Xcode I'm struggling with opening a view controller and closing it.
I tried to open it with this code:
#IBAction func didTapGame(){
let vc = storyboard?.instantiateViewController(identifier: "Game_VC") as! Game_ViewController
present(vc, animated: true)
}
and on the iPhones it seemed legit, but on the iPad it appeared modally as a screen on top of the homescreen of the app and too small so you could just tap it away on the side.
How do you properly present a view controller in code in storyboard and how do you close it again with a backbutton as I tried the backbutton the same way, but it just added a new homescreen on top of everything which isn't desirable of course, Thanks!
It is difficult to answers without more context, but if you have a UINavigationController you can try this:
self?.navigationController?.pushViewController(viewController: vc, animated: true)
My app is simply a UITableViewController embedded in a UINavigationController. In the main tableview controller viewDidLoad() method I check UserDefaults for a Boolean key to see if it is the first startup. If so, I modally present a UIPageViewController for a tutorial and onboarding.
self.present(tutorialViewController, animated: true, completion: nil)
However, underneath the tutorial screens, my main view controller’s navigationBar and toolBar change to a light grey colour until the tableview is interacted with, then they instantly change back to the default translucent appearance that I want. I cannot figure out what is causing this. I tried setting modalPresentationStyle to .overCurrentContext but this did not help.
I also get a warning that presenting view controllers on detached view controllers is discouraged. This warning goes away if I present it as follows:
self.parent?.present(tutorialViewController, animated: true, completion: nil)
This seems messy however, and the graphical artefact remains.
Am I presenting the tutorialViewController from the wrong place or in the wrong way? The tutorial screens seem to work as expected - it’s just the underlying navigation bar and toolbar briefly have the wrong colour. I need to present it over the tableview as the last page of the tutorial is transparent with a blur effect to help see how the app works.
I found the solution based on some discussion here.
I was presenting the modal view controller from the viewDidLoad() method when I should have done it in viewDidAppear().
I was also animating my tableview to fade in, so it was not visible before the tutorial screens. Instead, I’m now using a blocking view set to the same background colour as my tutorial view controller. In viewDidLoad() I do this:
let blockingView = UIView()
blockingView.frame = UIApplication.shared.keyWindow?.frame
UIApplication.shared.keyWindow?.addSubview(blockingView)
This means the blocking view appears in front of the navigation controller. I fade and remove the blockingView just before presenting the tutorial in viewDidAppear().
I want to show the view controller modally when I pressed the middle tab bar. I try to pick "over the screen" on presentation style, it work like modal but the transition style is not like the modal presentation.
Sorry I'm new in iOS. I need a custom tab bar tutorial that can show a view controller modally, I can't find it...
The layout similar like this:How to create tabbar with custom UI in swift 3.0
but can I do that without framework? because quite complicated for me..
For presenting viewController
self.present(ClassToPePresented(), animated: true, completion: nil)
For Pushing viewController
navigationController?.pushViewController(ClassToPePushed(), animated: true)
Modify class name as requirement
I'm using a navigation controller and it works great. However, some custom buttons segue to new ViewControllers (not in the stack) and I don't like the push-type transition animation it uses.
GOAL:
I want to the transitions (described above) to mimic a nav-stack pop transition (where the current view slides to right, revealing the view underneath).
I've successfully simulated a nav-pop using the below code, but then after my buttons and nav-bar back button are super glitchy.
#IBAction func Page2_to_Page1_ButPush(sender: AnyObject) {
var curPage: UIViewController = self.storyboard!.instantiateViewControllerWithIdentifier("Page2_ID") as! UIViewController
var prevPage: UIViewController = self.storyboard!.instantiateViewControllerWithIdentifier("Page1_ID") as! UIViewController
self.navigationController?.pushViewController(prevPage, animated: false)
self.navigationController?.pushViewController(curPage, animated: false)
self.navigationController?.popViewControllerAnimated(true)
}
Can anyone supply a simple way to make my segues simulate a nav-pop?
Details:
X-Code 6.4
Swift
Storyboard
Here's the solution:
iOS Segue - Left to Right -
Simple, easy, works perfect. Add the "SegueFromLeft" class code shown in the link, select the segue you want to present from left, select custom, pointed it at "SegueFromLeft", and the animation is dead on.
Bonus: Even better, it syncs up with the navigation controller, so the nav "Back" button still works.
In my tab based app, on clicking one of the tabs, I want to display a modal view controller with some info.
In my app delegate's didSelectViewController method, I am adding modal view. But it occupies entire screen and hides the tab bar. I don't want to hide the tab-bar, just want to display modal-view which pops up and can be dismissed.
How do I do it?
Please help.
Thanks in advance.
Modal view controllers are always presented full screen on an iPhone. If you don't want to hide the tab bar, then you need to present this view in some other way besides modal.
I was able to "present" a new view controller, over another, UNDER the tab bar, by setting modalPresentationStyle to .currentContext.
let newViewController = UIViewController()
newViewController.view.backgroundColor = UIColor.red
newViewController.modalPresentationStyle = .currentContext
newViewController.modalTransitionStyle = UIModalTransitionStyle.flipHorizontal
present(newViewController, animated: true, completion: nil)
Edit: From more testing, the above can have some buggy behavior if someone changes the tab WHILE the newViewController is presented.
To "fix," I created a "switcher" - a UIViewController that animates between the view controllers that I want to flip UNDER the tab bar:
view.addSubview(nextView)
UIView.transition(from: currentView,
to: nextView,
duration: 0.5,
options: animation,
completion: { (_) in
currentView.removeFromSuperview()
})
In this case, currentView is the view of ViewControllerOne (the currently visible one), and the nextView is view of ViewControllerTwo (the one we want to present).
For example if secondViewController is the second viewController for your second tabbar, you should do like this:
[secondViewController.view addSubview:theViewYouWantToShow];
In iOS , Modal View Controller is always have highest priority in all view controllers available. So you can not use Modal View Controller in your case.
If you just want to show popup on the screen with back ground visibility, then just use UIAlertView. You can add OK or CANCEL button as per your requirement to remove alert view.
Or
If you want to show a full view with tab bar visibility, then add the view in a that tab as a subview. You can give it a feel like a pop up using transform property of a view.
You can present it modally by setting PresentationStyle.This style presents viewController in a square and it does not occupy full screen.
self.modalPresentationStyle = UIModalPresentationFormSheet;
You can also set the transition:
self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;