Howto Size the Modal View programmatically (SWIFT)

梦想与她 提交于 2019-12-25 04:27:37

问题


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 ?


回答1:


  1. Try changing _popoverPresentationController.permittedArrowDirections to empty option set
  2. Change controller.preferredContentSize to match your desired size



回答2:


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.



来源:https://stackoverflow.com/questions/31586031/howto-size-the-modal-view-programmatically-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!