【问题标题】:can't handle size of a popover无法处理弹出框的大小
【发布时间】:2016-07-25 12:18:57
【问题描述】:

我想在 swift2,x-code 7.3 中创建一个类似于foursquare 的弹出菜单:

我正在使用此代码

//Create Pop up Menu
func setAnimatedMenu(identifier : String)-> ViewController{

    let storyboard : UIStoryboard = UIStoryboard(
        name: "Main",
        bundle: nil)
    let menuViewController: ViewController = storyboard.instantiateViewControllerWithIdentifier(identifier) as! ViewController//filters

    menuViewController.modalPresentationStyle = .OverFullScreen //played with this and tried every different styles
    menuViewController.preferredContentSize = CGSizeMake(self.view.frame.width, self.view.frame.height/3) //Played with this size, nothing changes

    let popoverMenuViewController = menuViewController.popoverPresentationController
    popoverMenuViewController?.permittedArrowDirections = .Any
    popoverMenuViewController?.delegate = self

    popoverMenuViewController?.sourceView = parentViewController?.view
    popoverMenuViewController?.sourceRect = CGRect(
        x: self.view.frame.size.width,
        y: self.view.frame.size.height/3,
        width: 1,
        height: 1) //played also with this size, nothing changes


    return menuViewController

}

我想要完成的是类似于图片中的内容,在当前视图和选项卡上弹出一个窗口,但上方视图的 1/3 可见。我只设法完成了全屏操作,如果我在弹出窗口中滚动并将其移动到底部或顶部,我只能看到后视图。

我尝试设置它的preferredContentSize,但该属性是不可变的:

这些是故事板属性:

编辑:我设法修复它,我没有意识到故事板设置窗口大小存在限制。我创建了一个高度约束的出口,只是从它解决了我的问题的代码中更改了它的值。

【问题讨论】:

    标签: ios objective-c swift swift2


    【解决方案1】:

    Y 位置是它在 Y 轴上的位置,因此您需要将其设置为:

    y: (self.view.frame.size.height/3) * 2.0,
    

    【讨论】:

    • 和以前完全一样。什么也没有变。可能是故事板中的问题吗?编辑添加带有属性的故事板图像
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    • 1970-01-01
    相关资源
    最近更新 更多