我正在尝试根据iPhone的倾斜度来设置Mapview(Mapbox)的动画效果。当角度大于45度时,MapView应设置为以底部为中心的圆形动画,当角度低于45度时,MapView应展开以填充整个屏幕。
我正在使用带约束的动画。动画无法正常运行:Gif of the Animation
这是我使用的代码:
if value > 45 {
UIView.animate(withDuration: 1.0, animations: {
self.mapView.frame = CGRect(x: self.mapViewInitialX, y: self.mapViewInitialY, width: 200, height: 200)
self.mapviewBottomConstraint.constant = 15
self.mapViewWidthConstraint.constant = 200
self.mapViewHeightConstraint.constant = 200
self.mapView.layer.cornerRadius = 100
self.mapView.layoutIfNeeded()
})
} else {
UIView.animate(withDuration: 1.0, animations: {
self.mapView.frame = CGRect(x: 0, y: 0, width: (self.mapView.superview?.bounds.width)!, height: (self.mapView.superview?.bounds.height)!)
self.mapviewBottomConstraint.constant = 0
self.mapViewWidthConstraint.constant = (self.mapView.superview?.bounds.width)!
self.mapViewHeightConstraint.constant = (self.mapView.superview?.bounds.height)!
self.mapView.layer.cornerRadius = 0
self.mapView.layoutIfNeeded()
})
}