【问题标题】:How to disable animation in TableView selection in Popover?如何在 Popover 的 TableView 选择中禁用动画?
【发布时间】:2016-06-22 10:20:21
【问题描述】:

单击单元格时会出现一个弹出框。在这个弹出窗口中,有一个带有一行的 TableView。当我单击该行时,会出现三个带有动画的新行。我想删除那个动画。有可能吗?

这是我的代码:

extension PlanningActionTableViewController
{
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return numberOfRows()
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCellWithIdentifier("ActionCell", forIndexPath: indexPath) as!PlanningActionCell


        // Info cells
        if registration == nil
        {
            if slot.registrations.count > indexPath.row
            {
                let contact = slot.registrations[indexPath.row].contact
                let name = contact.lastname + " " + contact.firstname
                cell.actionLabel.text = (name.characters.count > 1 ? name : "Réservation en cours")
                cell.accessoryType = .DisclosureIndicator
                cell.imageSymbol.image = UIImage(named: "picto.user.default")

                return cell
            }

            cell.actionLabel.text = "Ajouter"
            cell.accessoryType = .None
            cell.imageSymbol.image = UIImage(named: "picto.user.add")

            return cell

        }

        // Actions cell
        switch indexPath.row
        {
        case 0:
            cell.actionLabel.text = "Détails"
            cell.accessoryType = .None
            cell.imageSymbol.image = UIImage(named: "picto.user.details")

        case 1:
            var state = "Non"
            if let contact = registration?.contact
            {
                state = (contact.isArrived ? "Oui" : "Non")
            }

            cell.actionLabel.text = "Est arrivé: " + state
            cell.accessoryType = .None
            cell.imageSymbol.image = UIImage(named: "picto.user.valid")

        default:
            cell.actionLabel.text = "Supprimer booking"
            cell.actionLabel.textColor = UIColor.redColor()
            cell.imageSymbol.image = UIImage(named: "picto.user.delete")
            cell.accessoryType = .None
        }

        return cell
    }
}

行数:

func numberOfRows() -> Int
{
    if registration == nil
    {
        return slot.subslotsCount
    }

    return 3
}

视频示例:

<iframe src="//gifs.com/embed/1wvE6R" frameborder="0" scrolling="no" width='480' height='220.7665505226481' style="-webkit-backface-visibility: hidden;-webkit-transform: scale(1);" ></iframe>

【问题讨论】:

  • 首先,您的意思是什么动画,扩展弹出框或新行的外观,或两者兼而有之?其次,cellForRowAtIndexPath 方法本身不负责行动画,在扩展数据源的地方添加代码,即插入新行和/或更改 numberOfRows 的值。
  • 是新行的外观。当我显示三行(或更多)时,弹出框的动画会向下增加。
  • 如果您不想要动画,请计算您想要的弹出框的内容大小,手动设置并触发不带动画的数据源更新。
  • 没有别的办法了吗?我在视频中举了一个例子。奇怪的是,没有一个选项可以在没有动画的情况下执行它,或者只是通过更改动画来执行它?
  • 我觉得加上动画效果还不错。

标签: ios swift uitableview animation uipopovercontroller


【解决方案1】:

在您的 viewDidLoad 中,将动画设置为 false:

UIView.setAnimationsEnabled(false)

【讨论】:

  • 请注意,这将禁用通过UIView 静态调用执行的所有动画,这可能不是您想要的。
【解决方案2】:

您是否使用(现已弃用)UIPopoverController?如果是这样,您可以调用setPopoverContentSize(_ size: CGSize, animated animated: Bool),当然,将false 传递给animated 参数。只需计算三行表格的大小即可。

如果您使用具有模态演示样式的常规 UIViewController,则可以将内容的大小设置为计算出的表格大小。

【讨论】:

  • 嗯好的,我会检查的。谢谢:D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-24
  • 1970-01-01
相关资源
最近更新 更多