I have MainViewController
and AddViewController
that should be presented when the user clicks on a button in MainViewController
.
I've tried to use:
self.presentViewController(AddViewController(), animated: false, completion: nil)
but it presents it all over the screen (full screen).
I've searched for some answers in StackOverflow but I found a solution just for iPad.
So how can I present the view in the correct way?
Note: I set the AddViewController
's view's frame in the Xib
file.
You can use AddSubview function. Check this code.
Create a class file:
class MyClass: UIView {
class func instanceFromNib() -> UIView {
return UINib(nibName: "nib file name", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as UIView
}
}
Then you can use this class to grab the view from xib:
var myview = MyClass.instanceFromNib()
And then you can add this view wherever you want:
var presenterStoryBoard:UIStoryboard = UIStoryboard(name: "nameofstoryboard", bundle: nil)
var myview = MyClass.instanceFromNib()
var vc = presenterStoryBoard.instantiateInitialViewController() as MainViewController
publisherViewController.view.addSubview(myview.view)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.