2013-09-23 18 views
0

我想動畫一個UIButton,它是在我的UIView的底部,當鍵盤變爲/辭去第一響應者時。在iOS 7之前,我製作了一個簡單的動畫來移動按鈕,但現在鍵盤的動畫是非線性的,它的啓動速度更快,結束速度更慢。我被告知要用新的UIKit Dynamics來做,但不知道如何實現我的目標。任何建議?UIButton iOS 7以下UIKeyboard動畫

在此先感謝。

回答

4

收聽鍵盤通知。您可以獲得以下信息並相應地爲您的按鈕設置動畫。

UIKeyboardAnimationCurveUserInfoKey用於容納UIViewAnimationCurve常數定義如何 鍵盤將被動畫上或關閉屏幕一個NSNumber對象的鍵。

適用於iOS 3.0及更高版本。

在UIWindow.h中聲明。

UIKeyboardAnimationDurationUserInfoKey爲包含標識以秒爲 動畫的持續時間的雙一個NSNumber對象的鍵。

適用於iOS 3.0及更高版本。

在UIWindow.h中聲明。

點擊此處瞭解詳情: https://developer.apple.com/library/ios/documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html#//apple_ref/doc/constant_group/Keyboard_Notification_User_Info_Keys

+0

謝謝!像魅力一樣工作! – sergiocg90

0

possible duplicateanother possible duplicate

@Leo:我一直在使用這些值嘗試,但他們並沒有爲我工作(和其他人我見過)所以我結束了這個:

[UIView animateWithDuration:0.5 
         delay:0 
    usingSpringWithDamping:500.0f 
     initialSpringVelocity:0.0f 
        options:UIViewAnimationOptionCurveLinear 
       animations:animBlock 
       completion:completionBlock]; 
+0

當Apple更改動畫時,硬編碼值並不總是準確的,並且在版本之間往往會打破。 –