我想改變按鈕動作的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如果你會發布答案 - 我會讓它評分,導致它解決了我的問題!非常感謝! –