2014-11-21 51 views
0

我只是試圖以最簡單的方式向上移動兩個視圖,我無法弄清楚如何使它在iOS8上工作(但它的工作在iOS7上很好)。IOS 8.1的動畫問題

我讀過的變化發生,但我不能讓反正它的工作...

這裏是我使用的代碼:

的CGRect txFrame; //我的textview的初始框架 CGRect btFrame; //我的按鈕的初始幀

- (void)kbWillShow{ 

    [UIView animateWithDuration:0.45 animations:^{ 
      //Remembering the initial frames here 
      txFrame = _txReason.frame; 
      btFrame = _btSend.frame; 
      _lbTitleReason.alpha = 0.3; 
      //Animating 
      _txReason.frame = CGRectMake(txFrame.origin.x, txFrame.origin.y-55, txFrame.size.width, txFrame.size.height); 
      _btSend.frame = CGRectMake(btFrame.origin.x, btFrame.origin.y-75, btFrame.size.width, btFrame.size.height); 

     }completion:nil]; 

    } 

    - (void)kbWillHide{ 
    [UIView animateWithDuration:0.45 animations:^{ 
      //Putting them back to their original positions. 
      _txReason.frame = txFrame; 
      _btSend.frame = btFrame; 
      _lbTitleReason.alpha = 1; 
     }completion:nil]; 

    } 

我試圖把「結果」位置完成塊,但我只是做了非常突然和奇怪的運動,而duraton後視圖傳送點到intented位置。 (這比做一個突然的動作更好,並且最終在它開始的同一個位置結束)。

這應該很簡單,我做錯了什麼?

+0

在你的情況下,你應該使用'center'屬性來代替'frame'。 – holex 2014-11-21 15:41:39

+0

我想我已經嘗試過,但也許不正確,你能給我一個例子嗎? – Smiless 2014-11-21 15:44:03

+0

例子...?你應該做同樣的事情,但是用'center'屬性而不是'frame'。我不確定你想看哪個例子。編寫此註釋需要更多時間,而不是改變使用'center'屬性的實際代碼。 :) – holex 2014-11-21 15:46:55

回答

0

我遇到過這個問題,答案是要處理佈局約束。您需要更改影響要更改的視圖的佈局約束的常量屬性。

E.g.要更改寬度爲NSLayoutConstraint的視圖的寬度,您可以調用constraint.constant = newWidth;,然後繼續執行動畫代碼。這是我如何做的,它工作正常。

編輯:你的動畫代碼很好。你不需要玩centre屬性。

+0

我現在就試試這個,我回來了 – Smiless 2014-11-24 09:53:59