FS.O5 FS.O5 - 1 year ago 67
Swift Question

Present a view controller on top another one without full screen

I have

that should be presented when the user clicks on a button in

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
's view's frame in the

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download