如何快速将弹出窗口调整为表格视图中内容的大小? [英] How do I adjust my popover to the size of the content in my tableview in swift?

查看:106
本文介绍了如何快速将弹出窗口调整为表格视图中内容的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用popoverPresentationController来显示我的弹出窗口.用于显示为弹出窗口的UITableViewController是通过程序创建的,通常包含1至5行.如何设置此弹出窗口,以调整表格视图内容的大小?

I'm using popoverPresentationController to show my popover. The UITableViewController used to show as popover is created programmatically and will usually contain 1 to 5 rows. How do I set up this popover to adjust the size to the content of the tableview?

我的弹出窗口的代码:

if recognizer.state == .Began {
    let translation = recognizer.locationInView(view)

    // Create popoverViewController
    var popoverViewController = UITableViewController()
    popoverViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
    popoverViewController.tableView.backgroundColor = UIColor.popupColor()

    // Settings for the popover
    let popover = popoverViewController.popoverPresentationController!
    popover.delegate = self
    popover.sourceView = self.view
    popover.sourceRect = CGRect(x: translation.x, y: translation.y, width: 0, height: 0)
    popover.backgroundColor = UIColor.popupColor()

    presentViewController(popoverViewController, animated: true, completion: nil)
}

推荐答案

签出 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆