我正在將Objective-C中的應用程序移植到純Swift中,而且我正面臨着一個奇怪的問題。swift中的設置框架無法正常工作
我有AlertView
類,它是標準UIAlertView
(現在的UIAlertController
)的替代品,用於顯示動畫彈出窗口。 AlertView
創建於UIViewController
擴展名 - 它與視圖控制器的視圖框架一起插入並添加爲子視圖。
AlertView
有一個屬性,這是一個PopupView
的實例 - 自定義UIView
子類與xib(在Autolayout)。此彈出窗口應具有動態高度,具體取決於其內容(多行消息標籤)。
現在,當我試圖在AlertView
類動畫這個彈出:
- ,當我在設置
PopupView
setTranslatesAutoresizingMaskIntoConstraints(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)
setTranslatesAutoresizingMaskIntoConstraints(true)
請參閱此網址:http://stackoverflow.com/questions/29621114/method-presentviewcontroller-does-not-work-on-ios-8-3-after-update/29621571#29621571 – Rahul
@Rahul它不是案例 - 我沒有使用標準的'UIAlertView'和'UIAlertController' - 我用我的自定義'UIView'替換它們,並在'UIViewController'的擴展中顯示邏輯 – Kubba
你可以使用liceCap爲我們提供一個gif嗎? :) http://www.cockos.com/licecap/ – Zolnoor