【发布时间】:2015-04-07 11:06:14
【问题描述】:
我想在按钮操作上更改 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 如果您要发布答案 - 我会对其进行评分,因为它解决了我的问题!非常感谢!
标签: ios swift animation uiview mkmapview