2015-04-07 83 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

無論如何,它不適用於自動佈局。您需要調整約束並更新。 –