1
我有一個應用程序,在使用鍵盤時我將整個UIView
向上移動,以避免隱藏一些重要的UITextField
。UITableView在移動容器時調整大小UIView
我的問題是,我在那裏的UITableView
行爲與所有其他視圖的行爲不一樣。它不是移動整個UITableView
,而是移動其頂部邊緣,並調整UITableView
的大小,這不是預期的效果。
我的問題是更好的描述如下:http://www.youtube.com/watch?v=AVJVMiBULEQ
這是我使用動畫的代碼:
-(void)setViewMovedUp:(BOOL)movedUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5]; // if you want to slide up the view
[UIView setAnimationBeginsFromCurrentState:YES];
CGRect rect = self.view.frame;
if (movedUp) {
// 1. move the view's origin up so that the text field that will be hidden come above the keyboard
// 2. increase the size of the view so that the area behind the keyboard is covered up.
rect.origin.y -= 140;
rect.size.height += 140;
} else {
// revert back to the normal state.
rect.origin.y += 140;
rect.size.height -= 140;
}
self.view.frame = rect;
[UIView commitAnimations];
}
嗯,我總是通過設置變換self.transfom = CGAffineTransformMakeTranslation(0,-140)和self.transform = CGAffineTransformIdentity(向下移動)做到這一點。你可以試試這個,看看你是否得到相同的結果? –
謝謝。這工作,但它立即移動,沒有任何動畫。有什麼方法可以爲此添加動畫嗎? – Dimme
通過在Interface Builder中更改自動調整選項來解決。 =)它堅持調整大小。 – Dimme