0

Difficult to explain for me :-)

I already have: A main UIViewController/UIView -> works A second UIViewController/UIView which I show after a button is pressed -> works, second UIViewController/UIView is shown on top of screen and has the full screensize, so I can't see the first UIViewController/UIView

Because I realized my secondView holds only some small components, I would like: to show the second UIViewController/UIView over the first as like a popoverview, So the second is sized minimal and the first is still shown in the back.

I thought I could do simply the following:

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("Options") as! UIViewController

    vc.modalPresentationStyle = .Popover <<-- Make simply Modal ?

    self.presentViewController(vc, animated: true, completion: nil)

But still the second is shown on full screen. Any help ?

Update I just managed to do by combining stuff found in the internet without knowing what I exactly I am doing :-)

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.sourceView.sizeToFit();

    // present (id iPhone it is a modal automatic full screen)
    self.presentViewController(controller, animated: true, completion: nil)
}

}

The only prolem I have now is, that the size of the modal view is too small, some compontents are not fully visible.

mcfly soft
  • 11,289
  • 26
  • 98
  • 202
  • Not sure, if that helps. Probably I did not understand, but I do not want a popover with an arrow . I just want to show the UIView over the other. – mcfly soft Jul 23 '15 at 10:15
  • Take a look at this: http://stackoverflow.com/questions/24635744/how-to-present-popover-properly-in-ios-8/28158165#28158165 – Lars Christoffersen Jul 23 '15 at 18:57
  • Take a look at this answer, I posted long ago. http://stackoverflow.com/questions/24635744/how-to-present-popover-properly-in-ios-8/28158165#28158165 – Lars Christoffersen Jul 23 '15 at 19:01
  • take a look a this http://stackoverflow.com/questions/24635744/how-to-present-popover-properly-in-ios-8/28158165#28158165 – Lars Christoffersen Jul 23 '15 at 19:02

2 Answers2

1

Try changing controller.preferredContentSize to match your desired size

KleMiX
  • 322
  • 1
  • 13
  • Thanks. That heps. Do you know by chance howto get rid of the arrow ? – mcfly soft Jul 23 '15 at 13:53
  • I think I did answer that in your other [question](http://stackoverflow.com/questions/31586031/howto-size-the-modal-view-programmatically-swift/31588530#31588530) – KleMiX Jul 23 '15 at 13:58
0

Have you tried this? iOS -- how do you control the size of a modal view controller?

Bullet points: 1. do not use UIViewcontroller. use just UIView. 2. the first UIViewController's view will be unloaded if u loading a modal view controller.

Community
  • 1
  • 1
  • I don't think I can use an UIView itself, because I have buttons and interactions with standard control in my second UIViewController. I am not sure. I will check. – mcfly soft Jul 23 '15 at 10:49