Presenting a View Controller Modally
I am having issues using a View Controller modally for a sign in page. I can get the controller to appear but I can not change it from full size.
I am trying to present the popover in the center of the screen with a faded background. The popover should dismiss when I click outside of the view.
I have looked through the questions and answers throughout the site and have not found one that has worked for me.
Here is the code I have:
import UIKit
class SignInView: UIViewController, UIPopoverPresentationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "popoverSegue" {
var popover = segue.destination as! SignInPopView
popover.popoverPresentationController!.delegate = self
popover.modalPresentationStyle = UIModalPresentationStyle.popover
popover.preferredContentSize = CGSize(width: 375, height: 500)
}
}
ios swift modalviewcontroller
add a comment |
I am having issues using a View Controller modally for a sign in page. I can get the controller to appear but I can not change it from full size.
I am trying to present the popover in the center of the screen with a faded background. The popover should dismiss when I click outside of the view.
I have looked through the questions and answers throughout the site and have not found one that has worked for me.
Here is the code I have:
import UIKit
class SignInView: UIViewController, UIPopoverPresentationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "popoverSegue" {
var popover = segue.destination as! SignInPopView
popover.popoverPresentationController!.delegate = self
popover.modalPresentationStyle = UIModalPresentationStyle.popover
popover.preferredContentSize = CGSize(width: 375, height: 500)
}
}
ios swift modalviewcontroller
Is this on a phone or an iPad?
– Paulw11
Nov 24 '18 at 4:02
It could be used for either
– JSharpp
Nov 24 '18 at 4:24
I ask, because a popover is presented modally on an iPhone unless you tell iOS otherwise - stackoverflow.com/questions/39972979/…
– Paulw11
Nov 24 '18 at 4:28
add a comment |
I am having issues using a View Controller modally for a sign in page. I can get the controller to appear but I can not change it from full size.
I am trying to present the popover in the center of the screen with a faded background. The popover should dismiss when I click outside of the view.
I have looked through the questions and answers throughout the site and have not found one that has worked for me.
Here is the code I have:
import UIKit
class SignInView: UIViewController, UIPopoverPresentationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "popoverSegue" {
var popover = segue.destination as! SignInPopView
popover.popoverPresentationController!.delegate = self
popover.modalPresentationStyle = UIModalPresentationStyle.popover
popover.preferredContentSize = CGSize(width: 375, height: 500)
}
}
ios swift modalviewcontroller
I am having issues using a View Controller modally for a sign in page. I can get the controller to appear but I can not change it from full size.
I am trying to present the popover in the center of the screen with a faded background. The popover should dismiss when I click outside of the view.
I have looked through the questions and answers throughout the site and have not found one that has worked for me.
Here is the code I have:
import UIKit
class SignInView: UIViewController, UIPopoverPresentationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "popoverSegue" {
var popover = segue.destination as! SignInPopView
popover.popoverPresentationController!.delegate = self
popover.modalPresentationStyle = UIModalPresentationStyle.popover
popover.preferredContentSize = CGSize(width: 375, height: 500)
}
}
ios swift modalviewcontroller
ios swift modalviewcontroller
edited Nov 26 '18 at 4:57
JSharpp
asked Nov 24 '18 at 3:32
JSharppJSharpp
166113
166113
Is this on a phone or an iPad?
– Paulw11
Nov 24 '18 at 4:02
It could be used for either
– JSharpp
Nov 24 '18 at 4:24
I ask, because a popover is presented modally on an iPhone unless you tell iOS otherwise - stackoverflow.com/questions/39972979/…
– Paulw11
Nov 24 '18 at 4:28
add a comment |
Is this on a phone or an iPad?
– Paulw11
Nov 24 '18 at 4:02
It could be used for either
– JSharpp
Nov 24 '18 at 4:24
I ask, because a popover is presented modally on an iPhone unless you tell iOS otherwise - stackoverflow.com/questions/39972979/…
– Paulw11
Nov 24 '18 at 4:28
Is this on a phone or an iPad?
– Paulw11
Nov 24 '18 at 4:02
Is this on a phone or an iPad?
– Paulw11
Nov 24 '18 at 4:02
It could be used for either
– JSharpp
Nov 24 '18 at 4:24
It could be used for either
– JSharpp
Nov 24 '18 at 4:24
I ask, because a popover is presented modally on an iPhone unless you tell iOS otherwise - stackoverflow.com/questions/39972979/…
– Paulw11
Nov 24 '18 at 4:28
I ask, because a popover is presented modally on an iPhone unless you tell iOS otherwise - stackoverflow.com/questions/39972979/…
– Paulw11
Nov 24 '18 at 4:28
add a comment |
3 Answers
3
active
oldest
votes
This answer has worked for me:
https://stackoverflow.com/a/46518387/640588
class CommonViewController: UIViewController, UIPopoverPresentationControllerDelegate{
func adaptivePresentationStyle(
for controller: UIPresentationController,
traitCollection: UITraitCollection)
-> UIModalPresentationStyle {
return .none
}
func showPopover(){
let storyboard = UIStoryboard(name: "Pickers", bundle: nil)
let myViewController = UIViewController()
myViewController.preferredContentSize = CGSize(width: 320, height: 200)
myViewController.modalPresentationStyle = .popover
let popOver = myViewController.popoverPresentationController
popOver?.delegate = self
self.present(myViewController, animated: true, completion: nil)
popOver?.permittedArrowDirections = .init(rawValue: 0)
popOver?.sourceView = self.view
let rect = CGRect(
origin: CGPoint(x: self.view.frame.width/2, y: self.view.frame.height/2),
size: CGSize(width: 1, height: 1)
)
popOver?.sourceRect = rect
}
add a comment |
To make your view controller shown as a popup, you should set the following:
popupVC.modalPresentationStyle = .OverCurrentContext
popupVC.modalTransitionStyle = .CrossDissolve
And also design your view controller's position, size to make it look like a popup.
Also you can use EzPopup thats a nice pod
I use EzPopup and it worked for me
EzPopup does not seem to work in Swift 4
– JSharpp
Nov 26 '18 at 4:55
add a comment |
My solution was to create a modal segue to the new view controller. Place the content in a view within the view controller and set the view controllers background opacity to the desired amount. This can all be done through storyboard.
This way when the popover view controller appears the view appears where I want it, in the correct size, and the previous view controller is still visible behind the background.
The only issue I'm having with this is dismissing the modal popover when I click outside of the view.
This video was helpful: https://www.youtube.com/watch?v=S5i8n_bqblE
Edit: This Detect any tap outside the current view provided the solution to dismissing the modal when you touch outside of the view.
But that is not a popover.
– matt
Nov 25 '18 at 6:10
I suppose it's more of a modal or popup than a popover with the arrow. Either way it was exactly what I was looking for. I updated the answer with how to dismiss the modal when you touch outside the view.
– JSharpp
Nov 26 '18 at 4:05
But if that is what you were looking for, calling it a popover was unfair and misleading.
– matt
Nov 26 '18 at 4:53
I agree, it was an honest mistake since they are very similar. I will change the title of the question to prevent confusion. This is a fully functional solution to the general problem either way.
– JSharpp
Nov 26 '18 at 4:56
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454935%2fpresenting-a-view-controller-modally%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
This answer has worked for me:
https://stackoverflow.com/a/46518387/640588
class CommonViewController: UIViewController, UIPopoverPresentationControllerDelegate{
func adaptivePresentationStyle(
for controller: UIPresentationController,
traitCollection: UITraitCollection)
-> UIModalPresentationStyle {
return .none
}
func showPopover(){
let storyboard = UIStoryboard(name: "Pickers", bundle: nil)
let myViewController = UIViewController()
myViewController.preferredContentSize = CGSize(width: 320, height: 200)
myViewController.modalPresentationStyle = .popover
let popOver = myViewController.popoverPresentationController
popOver?.delegate = self
self.present(myViewController, animated: true, completion: nil)
popOver?.permittedArrowDirections = .init(rawValue: 0)
popOver?.sourceView = self.view
let rect = CGRect(
origin: CGPoint(x: self.view.frame.width/2, y: self.view.frame.height/2),
size: CGSize(width: 1, height: 1)
)
popOver?.sourceRect = rect
}
add a comment |
This answer has worked for me:
https://stackoverflow.com/a/46518387/640588
class CommonViewController: UIViewController, UIPopoverPresentationControllerDelegate{
func adaptivePresentationStyle(
for controller: UIPresentationController,
traitCollection: UITraitCollection)
-> UIModalPresentationStyle {
return .none
}
func showPopover(){
let storyboard = UIStoryboard(name: "Pickers", bundle: nil)
let myViewController = UIViewController()
myViewController.preferredContentSize = CGSize(width: 320, height: 200)
myViewController.modalPresentationStyle = .popover
let popOver = myViewController.popoverPresentationController
popOver?.delegate = self
self.present(myViewController, animated: true, completion: nil)
popOver?.permittedArrowDirections = .init(rawValue: 0)
popOver?.sourceView = self.view
let rect = CGRect(
origin: CGPoint(x: self.view.frame.width/2, y: self.view.frame.height/2),
size: CGSize(width: 1, height: 1)
)
popOver?.sourceRect = rect
}
add a comment |
This answer has worked for me:
https://stackoverflow.com/a/46518387/640588
class CommonViewController: UIViewController, UIPopoverPresentationControllerDelegate{
func adaptivePresentationStyle(
for controller: UIPresentationController,
traitCollection: UITraitCollection)
-> UIModalPresentationStyle {
return .none
}
func showPopover(){
let storyboard = UIStoryboard(name: "Pickers", bundle: nil)
let myViewController = UIViewController()
myViewController.preferredContentSize = CGSize(width: 320, height: 200)
myViewController.modalPresentationStyle = .popover
let popOver = myViewController.popoverPresentationController
popOver?.delegate = self
self.present(myViewController, animated: true, completion: nil)
popOver?.permittedArrowDirections = .init(rawValue: 0)
popOver?.sourceView = self.view
let rect = CGRect(
origin: CGPoint(x: self.view.frame.width/2, y: self.view.frame.height/2),
size: CGSize(width: 1, height: 1)
)
popOver?.sourceRect = rect
}
This answer has worked for me:
https://stackoverflow.com/a/46518387/640588
class CommonViewController: UIViewController, UIPopoverPresentationControllerDelegate{
func adaptivePresentationStyle(
for controller: UIPresentationController,
traitCollection: UITraitCollection)
-> UIModalPresentationStyle {
return .none
}
func showPopover(){
let storyboard = UIStoryboard(name: "Pickers", bundle: nil)
let myViewController = UIViewController()
myViewController.preferredContentSize = CGSize(width: 320, height: 200)
myViewController.modalPresentationStyle = .popover
let popOver = myViewController.popoverPresentationController
popOver?.delegate = self
self.present(myViewController, animated: true, completion: nil)
popOver?.permittedArrowDirections = .init(rawValue: 0)
popOver?.sourceView = self.view
let rect = CGRect(
origin: CGPoint(x: self.view.frame.width/2, y: self.view.frame.height/2),
size: CGSize(width: 1, height: 1)
)
popOver?.sourceRect = rect
}
answered Nov 24 '18 at 5:02
GomfuciusGomfucius
1,7391932
1,7391932
add a comment |
add a comment |
To make your view controller shown as a popup, you should set the following:
popupVC.modalPresentationStyle = .OverCurrentContext
popupVC.modalTransitionStyle = .CrossDissolve
And also design your view controller's position, size to make it look like a popup.
Also you can use EzPopup thats a nice pod
I use EzPopup and it worked for me
EzPopup does not seem to work in Swift 4
– JSharpp
Nov 26 '18 at 4:55
add a comment |
To make your view controller shown as a popup, you should set the following:
popupVC.modalPresentationStyle = .OverCurrentContext
popupVC.modalTransitionStyle = .CrossDissolve
And also design your view controller's position, size to make it look like a popup.
Also you can use EzPopup thats a nice pod
I use EzPopup and it worked for me
EzPopup does not seem to work in Swift 4
– JSharpp
Nov 26 '18 at 4:55
add a comment |
To make your view controller shown as a popup, you should set the following:
popupVC.modalPresentationStyle = .OverCurrentContext
popupVC.modalTransitionStyle = .CrossDissolve
And also design your view controller's position, size to make it look like a popup.
Also you can use EzPopup thats a nice pod
I use EzPopup and it worked for me
To make your view controller shown as a popup, you should set the following:
popupVC.modalPresentationStyle = .OverCurrentContext
popupVC.modalTransitionStyle = .CrossDissolve
And also design your view controller's position, size to make it look like a popup.
Also you can use EzPopup thats a nice pod
I use EzPopup and it worked for me
edited Nov 24 '18 at 5:07
answered Nov 24 '18 at 5:01
alireza kianialireza kiani
12
12
EzPopup does not seem to work in Swift 4
– JSharpp
Nov 26 '18 at 4:55
add a comment |
EzPopup does not seem to work in Swift 4
– JSharpp
Nov 26 '18 at 4:55
EzPopup does not seem to work in Swift 4
– JSharpp
Nov 26 '18 at 4:55
EzPopup does not seem to work in Swift 4
– JSharpp
Nov 26 '18 at 4:55
add a comment |
My solution was to create a modal segue to the new view controller. Place the content in a view within the view controller and set the view controllers background opacity to the desired amount. This can all be done through storyboard.
This way when the popover view controller appears the view appears where I want it, in the correct size, and the previous view controller is still visible behind the background.
The only issue I'm having with this is dismissing the modal popover when I click outside of the view.
This video was helpful: https://www.youtube.com/watch?v=S5i8n_bqblE
Edit: This Detect any tap outside the current view provided the solution to dismissing the modal when you touch outside of the view.
But that is not a popover.
– matt
Nov 25 '18 at 6:10
I suppose it's more of a modal or popup than a popover with the arrow. Either way it was exactly what I was looking for. I updated the answer with how to dismiss the modal when you touch outside the view.
– JSharpp
Nov 26 '18 at 4:05
But if that is what you were looking for, calling it a popover was unfair and misleading.
– matt
Nov 26 '18 at 4:53
I agree, it was an honest mistake since they are very similar. I will change the title of the question to prevent confusion. This is a fully functional solution to the general problem either way.
– JSharpp
Nov 26 '18 at 4:56
add a comment |
My solution was to create a modal segue to the new view controller. Place the content in a view within the view controller and set the view controllers background opacity to the desired amount. This can all be done through storyboard.
This way when the popover view controller appears the view appears where I want it, in the correct size, and the previous view controller is still visible behind the background.
The only issue I'm having with this is dismissing the modal popover when I click outside of the view.
This video was helpful: https://www.youtube.com/watch?v=S5i8n_bqblE
Edit: This Detect any tap outside the current view provided the solution to dismissing the modal when you touch outside of the view.
But that is not a popover.
– matt
Nov 25 '18 at 6:10
I suppose it's more of a modal or popup than a popover with the arrow. Either way it was exactly what I was looking for. I updated the answer with how to dismiss the modal when you touch outside the view.
– JSharpp
Nov 26 '18 at 4:05
But if that is what you were looking for, calling it a popover was unfair and misleading.
– matt
Nov 26 '18 at 4:53
I agree, it was an honest mistake since they are very similar. I will change the title of the question to prevent confusion. This is a fully functional solution to the general problem either way.
– JSharpp
Nov 26 '18 at 4:56
add a comment |
My solution was to create a modal segue to the new view controller. Place the content in a view within the view controller and set the view controllers background opacity to the desired amount. This can all be done through storyboard.
This way when the popover view controller appears the view appears where I want it, in the correct size, and the previous view controller is still visible behind the background.
The only issue I'm having with this is dismissing the modal popover when I click outside of the view.
This video was helpful: https://www.youtube.com/watch?v=S5i8n_bqblE
Edit: This Detect any tap outside the current view provided the solution to dismissing the modal when you touch outside of the view.
My solution was to create a modal segue to the new view controller. Place the content in a view within the view controller and set the view controllers background opacity to the desired amount. This can all be done through storyboard.
This way when the popover view controller appears the view appears where I want it, in the correct size, and the previous view controller is still visible behind the background.
The only issue I'm having with this is dismissing the modal popover when I click outside of the view.
This video was helpful: https://www.youtube.com/watch?v=S5i8n_bqblE
Edit: This Detect any tap outside the current view provided the solution to dismissing the modal when you touch outside of the view.
edited Nov 26 '18 at 4:06
answered Nov 25 '18 at 4:45
JSharppJSharpp
166113
166113
But that is not a popover.
– matt
Nov 25 '18 at 6:10
I suppose it's more of a modal or popup than a popover with the arrow. Either way it was exactly what I was looking for. I updated the answer with how to dismiss the modal when you touch outside the view.
– JSharpp
Nov 26 '18 at 4:05
But if that is what you were looking for, calling it a popover was unfair and misleading.
– matt
Nov 26 '18 at 4:53
I agree, it was an honest mistake since they are very similar. I will change the title of the question to prevent confusion. This is a fully functional solution to the general problem either way.
– JSharpp
Nov 26 '18 at 4:56
add a comment |
But that is not a popover.
– matt
Nov 25 '18 at 6:10
I suppose it's more of a modal or popup than a popover with the arrow. Either way it was exactly what I was looking for. I updated the answer with how to dismiss the modal when you touch outside the view.
– JSharpp
Nov 26 '18 at 4:05
But if that is what you were looking for, calling it a popover was unfair and misleading.
– matt
Nov 26 '18 at 4:53
I agree, it was an honest mistake since they are very similar. I will change the title of the question to prevent confusion. This is a fully functional solution to the general problem either way.
– JSharpp
Nov 26 '18 at 4:56
But that is not a popover.
– matt
Nov 25 '18 at 6:10
But that is not a popover.
– matt
Nov 25 '18 at 6:10
I suppose it's more of a modal or popup than a popover with the arrow. Either way it was exactly what I was looking for. I updated the answer with how to dismiss the modal when you touch outside the view.
– JSharpp
Nov 26 '18 at 4:05
I suppose it's more of a modal or popup than a popover with the arrow. Either way it was exactly what I was looking for. I updated the answer with how to dismiss the modal when you touch outside the view.
– JSharpp
Nov 26 '18 at 4:05
But if that is what you were looking for, calling it a popover was unfair and misleading.
– matt
Nov 26 '18 at 4:53
But if that is what you were looking for, calling it a popover was unfair and misleading.
– matt
Nov 26 '18 at 4:53
I agree, it was an honest mistake since they are very similar. I will change the title of the question to prevent confusion. This is a fully functional solution to the general problem either way.
– JSharpp
Nov 26 '18 at 4:56
I agree, it was an honest mistake since they are very similar. I will change the title of the question to prevent confusion. This is a fully functional solution to the general problem either way.
– JSharpp
Nov 26 '18 at 4:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454935%2fpresenting-a-view-controller-modally%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is this on a phone or an iPad?
– Paulw11
Nov 24 '18 at 4:02
It could be used for either
– JSharpp
Nov 24 '18 at 4:24
I ask, because a popover is presented modally on an iPhone unless you tell iOS otherwise - stackoverflow.com/questions/39972979/…
– Paulw11
Nov 24 '18 at 4:28