2015-04-22 81 views
0

我正在將Objective-C中的應用程序移植到純Swift中,而且我正面臨着一個奇怪的問題。swift中的設置框架無法正常工作

我有AlertView類,它是標準UIAlertView(現在的UIAlertController)的替代品,用於顯示動畫彈出窗口。 AlertView創建於UIViewController擴展名 - 它與視圖控制器的視圖框架一起插入並添加爲子視圖。

AlertView有一個屬性,這是一個PopupView的實例 - 自定義UIView子類與xib(在Autolayout)。此彈出窗口應具有動態高度,具體取決於其內容(多行消息標籤)。

現在,當我試圖在AlertView類動畫這個彈出:

  • ,當我在設置PopupViewsetTranslatesAutoresizingMaskIntoConstraints(false) - 視圖的高度是正確的,但其設定在動畫幀不能按預期工作 - 觀點粘在左上角
  • 當我設置setTranslatesAutoresizingMaskIntoConstraints(true) - 動漫作品作爲預期,但鑑於有廈門國際銀行從大小(根據內容將不會擴大)

可以採取什麼錯在這裏?

EDIT 顯示彈出方法:

private func showPopup(popupView: PopupView) 
{ 
    var beginFrame = popupView.frame 
    beginFrame.origin.y = -beginFrame.size.height 
    beginFrame.origin.x = self.bounds.size.width/2 - beginFrame.width/2 
    popupView.frame = beginFrame 

    var endFrame = beginFrame 
    endFrame.origin.y = self.bounds.size.height/2 - endFrame.size.height/2 

    popupView.hidden = false 
    DLog(beginFrame) 

    UIView.animateWithDuration(kAnimationTime, delay: 0, usingSpringWithDamping: kAnimationDamping, initialSpringVelocity: kAnimationSpringVelocity, options: UIViewAnimationOptions.CurveEaseIn, animations: 
     {() -> Void in 
      DLog(endFrame) 
      popupView.frame = endFrame 
    }, completion: nil) 
} 
在這兩種情況下它示出了在控制檯

(72.5,-155.0,230.0,155.0)

(72.5,256.0,230.0, 155.0)

EDIT2

setTranslatesAutoresizingMaskIntoConstraints(false)

set-false

setTranslatesAutoresizingMaskIntoConstraints(true)

set-true

+0

請參閱此網址:http://stackoverflow.com/questions/29621114/method-presentviewcontroller-does-not-work-on-ios-8-3-after-update/29621571#29621571 – Rahul

+0

@Rahul它不是案例 - 我沒有使用標準的'UIAlertView'和'UIAlertController' - 我用我的自定義'UIView'替換它們,並在'UIViewController'的擴展中顯示邏輯 – Kubba

+0

你可以使用liceCap爲我們提供一個gif嗎? :) http://www.cockos.com/licecap/ – Zolnoor

回答

1

好,我知道的解決方案。我已停止混合自動佈局和直接修改幀,並使用純自動佈局。