2017-04-06 82 views
2

iOS的10,雨燕3.1动画效果自动布局约束不工作

我有一个名为UIView一个graphPopupUITableViewCell我试图动画里面。基本上,当有人点击一个图表时,出现一个弹出窗口,我希望它将其xy设置到位。

除弹出窗口的动画外,一切正常。下面是它现在的样子: enter image description here

我从点至点到位想要的弹出窗口幻灯片。这里是我的代码:

class TotalCell: UITableViewCell, ChartViewDelegate{ 

    @IBOutlet weak var graphPopup: UIView! 
    @IBOutlet weak var popupConstraintY: NSLayoutConstraint! 
    @IBOutlet weak var popupConstraintX: NSLayoutConstraint! 

    func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) { 
    //... 
    graphPopup.isHidden = false 

    //Set new auto layout constraints 
    self.popupConstraintX.constant = highlight.xPx-44 
    self.popupConstraintY.constant = highlight.yPx+18 

    //Animate (which does nothing) 
    UIView.animate(withDuration: 1.0, animations: { 
     self.graphPopup.layoutIfNeeded() 
    }) 
    } 
} 

任何想法我可能做错了什么?如果我完全删除动画位,它的行为方式相同,但我知道动画正在被调用。

任何想法?

+1

有两个问题 - 您是否尝试过在'self'上调用'layoutIfNeeded()',放入'graphPopup'?第二 - 你在哪里隐藏弹出窗口?你有没有试图保持它始终可见?这很奇怪,但也许动画发生时,它不可见? – Losiowaty

回答

5

尝试self.layoutIfNeeded()而不是self.graphPopup.layoutIfNeeded()