我已經在我的應用程序如下界面佈局的觀點:iOS版 - 接口單元重疊的時候把
當我在文本字段上單擊(如果你舔添加標籤添加一個新文本字段)我把我的觀點向上滾動,以不通過鍵盤進行遮擋,使用戶可以正確地看到他正在打字,但是當我這樣做會發生以下情況:
這是我使用的代碼進行切換:
- (void)keyboardWillShow:(NSNotification *)notification {
if (self.keyboardIsShown) {
return;
}
NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [keyboardBoundsValue CGRectValue].size;
NSTimeInterval animationDuration = 0.3;
CGRect frame = self.view.frame;
frame.origin.y -= keyboardSize.height - 94 + self.firstResponder.superview.superview.frame.origin.y;
frame.size.height += keyboardSize.height - 94 + self.firstResponder.superview.superview.frame.origin.y;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:animationDuration];
self.view.frame = frame;
[UIView commitAnimations];
self.keyboardIsShown = YES;
}
- (void)keyboardWillHide:(NSNotification *)notification {
NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [keyboardBoundsValue CGRectValue].size;
NSTimeInterval animationDuration = 0.3;
CGRect frame = self.view.frame;
frame.origin.y += keyboardSize.height - 94 + self.firstResponder.superview.superview.frame.origin.y;
frame.size.height -= keyboardSize.height - 94 + self.firstResponder.superview.superview.frame.origin.y;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:animationDuration];
self.view.frame = frame;
[UIView commitAnimations];
self.keyboardIsShown = NO;
}
任何想法,我怎樣才能使視圖元素顯示導航欄或消失或其他變通方法,將正常工作的背後?
它都是在故事板中創建的,但add標籤中的附加表格視圖單元格除外。 – 8vius
因此,將您在視圖控制器主視圖內的視圖中移動的內容封裝起來。問題是,你正在移動視圖控制器的主視圖,你不應該這樣做。 –
好的,我應該怎麼做?有像你這樣的子視圖,把所有東西都包起來了嗎? – 8vius