此代碼在ios 7中運行得非常漂亮。但是,使用ios8和xcode 6.0.1時,它已停止工作。當用戶點擊文本字段輸入文本時,該字段會在鍵盤頂部上方浮動,以便他們可以看到他們正在鍵入的內容。任何想法爲什麼這個失敗現在。我可以看到它開始動畫的瞬間,但隨後文本字段消失。令人沮喪。TextField動畫破碎ios8
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.4];
[UIView setAnimationBeginsFromCurrentState:YES];
textField.frame = CGRectMake(textField.frame.origin.x, (textField.frame.origin.y - 200.0),
textField.frame.size.width, textField.frame.size.height);
_searchBtn.frame = CGRectMake(_searchBtn.frame.origin.x, (_searchBtn.frame.origin.y - 200.0),
_searchBtn.frame.size.width, _searchBtn.frame.size.height);
[UIView commitAnimations];
textField.alpha = .75;
}
看起來像你有以下人一樣的問題http://stackoverflow.com/questions/26045048/how-to-implement-newsfeed-comment-page-similar-to-facebook-or-instagram。也許他的問題對你有一些答案。如果他的問題包括你的問題,你應該加大力度以引起更多關注。但我的猜測是他的問題會幫助你一點。例如你的200是硬編碼的。但是,你應該看着鍵盤通知,以便提取高度。對於測試,請嘗試將數字更改爲250並查看會發生什麼情況。 – 2014-09-25 18:55:12
感謝您的回覆,Konsol。我試着將代碼動態調整到鍵盤的實際高度,但仍然沒有運氣。我也試着玩這些數字。非常感謝您的建議。有人必須爲此做出回答! – hansoac 2014-09-25 19:09:59