Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将子视图定位在视图控制器中按钮的左下角下方?_Ios_Swift - Fatal编程技术网

Ios 如何将子视图定位在视图控制器中按钮的左下角下方?

Ios 如何将子视图定位在视图控制器中按钮的左下角下方?,ios,swift,Ios,Swift,我在视图控制器的顶部有一个选项按钮(3个垂直虚线按钮)。 当我点击该按钮时,列表视图应该会像WhatsApp等其他应用程序一样出现。。。 我真的不知道如何以编程方式将其放置在按钮附近。将其放置在现有视图的左下角相当容易: func placeSubView(existingView: UIView) { let desiredWidth = CGFloat(50.0) let desiredHeight = CGFloat(35.0) let (x, y) = (exis

我在视图控制器的顶部有一个选项按钮(3个垂直虚线按钮)。 当我点击该按钮时,列表视图应该会像WhatsApp等其他应用程序一样出现。。。
我真的不知道如何以编程方式将其放置在按钮附近。

将其放置在现有视图的左下角相当容易:

func placeSubView(existingView: UIView)
{
    let desiredWidth = CGFloat(50.0)
    let desiredHeight = CGFloat(35.0)
    let (x, y) = (existingView.frame.origin.x - desiredWidth, existingView.frame.origin.y + existingView.frame.size.height)

    let desiredView = UIView(frame: CGRect(x: x, y: y, width: desiredWidth, height: desiredHeight))

    existingView.superview?.addSubview(desiredView)
}
更新:

如果您正在寻找类似于弹出式菜单的视图,您应该搜索关于


类似于。

如果需要列表,请使用此方法并将PopoverViewController设置为表视图控制器

@IBAction func displayPopover(_ sender: UIBarButtonItem) {
    let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewController(withIdentifier: "PopoverViewController")
    vc.modalPresentationStyle = .popover
    let popover: UIPopoverPresentationController = vc.popoverPresentationController!
    popover.barButtonItem = sender
    present(vc, animated: true, completion:nil)
}

单击该按钮时,可以添加自定义视图