我想改变按钮动作的mapView的大小,所以我有两个功能来做到这一点。动画不执行
func makeFullScreenMap() {
println(self.heightConstraint.constant)
self.heightConstraint.constant = self.tableView.frame.height
println(self.heightConstraint.constant)
self.mapView.setNeedsUpdateConstraints()
UIView.animateWithDuration(5, animations: {() -> Void in
self.mapView.layoutIfNeeded()
})
}
func makeHideScreenMap() {
self.heightConstraint.constant = 0
self.mapView.setNeedsUpdateConstraints()
UIView.animateWithDuration(5, animations: {() -> Void in
self.mapView.layoutIfNeeded()
})
}
其他,我有行动,我跟踪按钮状态,并选择我需要使用什么确切的方法。
@IBAction func fullScreen(sender: AnyObject) {
println(changeMapButton.state.rawValue)
if changeMapButton.state == UIControlState.Highlighted {
makeFullScreenMap()
changeMapButton.selected = true
} else {
changeMapButton.highlighted = true
makeHideScreenMap()
}
}
问题是 - 当它动画时,它使动画变慢,并使mapView变得更大。当我使用方法makeHideScreenMap()时,它正在改变,然后滚动地图视图动画。我需要它像变动的框架一样慢慢动画。任何建议?
你可以尝试用self.view.layoutIfNeeded()在动画块中替换self.mapView吗? – Greg
@Greg如果你会发布答案 - 我会让它评分,导致它解决了我的问题!非常感谢! –