[SWIFT]Presenting Modal View Controller with transparency in ios7 - swift

Im trying to present a modal view controller in my app with the background transparent, it works for ios8, but for some reason in ios7 the background becomes gray and doesnt show transparency, Ive already set the alpha to the view in storyboard and below is the code Im using:
let storyboard = UIStoryboard(name: "PopUpStoryboard", bundle: nil);
let vc = storyboard.instantiateViewControllerWithIdentifier("PopUpQuestionController") as PopUpQuestionController;
vc.currentEvent = self.currentEvent
vc.questionMode = "text"
self.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
self.presentViewController(vc, animated: true, completion: nil);
the result in ios8:
and the result in ios 7:
anyone can help me with this?

Related

How to display the tabBar on the screen after the transition

I'm a beginner developing iOS apps using swift in Xcode.
[embarrassment]
I would like to know how to display tabBar on the screen after the transition by button.
If you press the button in FistViewController in the image below, you will go to nextViewController on the right side. I would like to know how to display the tabBar in nextViewController as well. (If you press the button to transition through the screen, the nextViewController will not display the tabBar.)
When you present a view controller modally, its presentation style will be "Full Screen" by default.What you need to do is change your modalPresentationStyle
guard let VC = self.storyboard?.instantiateViewController(withIdentifier: "yourVCName") else {
return
}
self.definesPresentationContext = true
VC.modalPresentationStyle = .overCurrentContext
self.present(VC, animated: true, completion: nil)

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)

Present viewcontroller with tabbar

I created UITabBarController programmatically in AppDelegate with 4 view controllers(using .xib). When user tap some button on ViewController (VC-A) it present another VC (VC-B) and covered tabbar. So I want to VC-B has a tabbar on the button.
I tried to add VC-B as a child of tabbarcontroller. I tried to .present(vc) and .show(vc) on both: VC-A and VC-A.TabBarController
Creating controllers in AppDelegate:
let controllers = [tabViewController1,tabViewController2,tabViewController3,tabViewController4]
tabBarController.viewControllers = controllers
window?.rootViewController = tabBarController
presenting in VC-A
self.tabBarController?.present(controller, animated: false, completion: nil)
right click and drag from tabbar controller in storyboard to VC-B. that should create a tab on the bottom of your VC-A and VC-B to go back and forth without having to implement any backend code unless you want to animate
The solution is to embed every VC in navigationController and then add to TabBarController.
let vc1 = ViewController1()
let navController1 = UINavigationController(rootViewController: vc1)
navController.isNavigationBarHidden = true
let controllers = [navController1, navController2, navController3, navController4]
tabBarController.viewControllers = controllers
window?.rootViewController = tabBarController
Then call
self.navigationController?.pushViewController(controller, animated:
true)
To diplay VC with tabbar
I will press the red login button at the bottom of the picture and try to log in.
login button => "로그인"
After that, log in.
let moreVC = self.storyboard?.instantiateViewController(withIdentifier: "MoreViewController") as! MoreViewController
moreVC.definesPresentationContext = true
moreVC.modalPresentationStyle = .fullScreen
let navController = UINavigationController(rootViewController: moreVC)
self.present(navController, animated: true, completion: nil)
If the login proceeds without error, the above code will be called to display the screen when the login is completed.
If the flow proceeds as the code above, this screen appears.
The screen shown is not fullscreen, and the tabbar at the bottom is gone. The screen I want is the screen below.
How can I present a tab bar when presenting the screen?

How to make transparent to second View controller using Swift

I have really trouble to make transparent a view controller. I have 2 view controller. and trying to make transparent second view controller.
This is my first view controller.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let destViewController : SearchViewController = storyboard.instantiateViewController(withIdentifier: "SearchViewController") as! SearchViewController
destViewController.getSearchTxt = self.tagsData[indexPath.row]
// destViewController.modalPresentationStyle = .currentContext
destViewController.modalPresentationStyle = .overCurrentContext
self.navigationController!.pushViewController(destViewController, animated: true)
this is my second view controller.
self.view.isOpaque = false
self.view.backgroundColor = .clear
black background is displaying instead of trasparent
For UINavigationController displaying .overCurrentContext is impossible. If you want to display it overCurrentContext use present
self.present(destViewController, animated: true)
If pushViewController is really required you can try to save the previous view to image and add it as a subview to the new SearchViewController.view.

Howto Size the Modal View programmatically (SWIFT)

I simply want to present a small option dialog over an existing main UIViewController/UIView , so that on an IPad I would see a small Dialog and in the Background I will see the Main View.
I managed to show a UIViewController/UIView in a modal view style as follow:
func showoptions(){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier("Options") as! UIViewController
controller.modalPresentationStyle = UIModalPresentationStyle.Popover
let popoverPresentationController = controller.popoverPresentationController
// result is an optional (but should not be nil if modalPresentationStyle is popover)
if let _popoverPresentationController = popoverPresentationController {
// set the view from which to pop up
_popoverPresentationController.sourceView = self.view;
//_popoverPresentationController.sourceRect = CGRectMake(60, 100, 500, 500)
//_popoverPresentationController. .setPopoverContentSize(CGSizeMake(550, 600), animated: true)
//_popoverPresentationController.sourceView.sizeToFit();
// present (id iPhone it is a modal automatic full screen)
self.presentViewController(controller, animated: true, completion: nil)
}
}
But I have still some issues:
1. Howto get rid of the arrow shown at the border.
2. Howto size this modal view. It is shown to small and I would like to fit it to the largest controls in the UIControllerView/UIView.
any help ?
Try changing _popoverPresentationController.permittedArrowDirections to empty option set
Change controller.preferredContentSize to match your desired size
I needed something similar and ended up presenting a view controller as a modal with a transparent background over the current context. There I made a smaller opaque UIView with what I wanted.