2015-04-07 48 views
0

我想改变按钮动作的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()时,它正在改变,然后滚动地图视图动画。我需要它像变动的框架一样慢慢动画。任何建议?

+2

你可以尝试用self.view.layoutIfNeeded()在动画块中替换self.mapView吗? – Greg

+0

@Greg如果你会发布答案 - 我会让它评分,导致它解决了我的问题!非常感谢! –

回答

2

你应该self.view.layoutIfNeeded()取代self.mapView.layoutIfNeeded()动画块内,因为你的布局约束的视图的孩子不MapView的。

0

尝试使用此动画。请根据您的需要管理坐标。

let trans = CGAffineTransformScale(mapView.transform, 1.00, 1.00) 
UIView .animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { 

     self. mapView.transform = CGAffineTransformScale(self. mapView.transform, 100.0, 100.0) 

     }, completion: { 
      (value: Bool) in 
    }) 
+0

我需要改变一些约束,所以你的代码不会帮助我在我的需要 –

+0

无论如何,它不适用于自动布局。您需要调整约束并更新。 –