0
嗨 我使用以下來提高鍵盤,我有很多視圖控制器也可以使用它,但我的嘗試委派失敗。我絕對不希望將其插入到每個視圖控制器中。如果任何想法Iphone代表
- (void)viewWillAppear:(BOOL)animated {
void (^keyBoardWillShow) (NSNotification *)= ^(NSNotification * notif) {
NSDictionary* info = [notif userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
float bottomPoint = (ivcTextField.frame.origin.y + ivcTextField.frame.size.height + 10);
scrollAmount = keyboardSize.height - (self.view.frame.size.height - bottomPoint);
if (scrollAmount > 0) {
moveViewUp =YES;
[self scrollTheView:YES];
}
else
moveViewUp = NO;
};
[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification object:self.view.window queue:nil
usingBlock:keyBoardWillShow];
void (^keyBoardWillHide) (NSNotification *)= ^(NSNotification * notif) {
if (moveViewUp) [self scrollTheView:NO];
};
[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillHideNotification object:self.view.window queue:nil
usingBlock:keyBoardWillHide];
[super viewWillAppear:animated];
} 將不勝感激 - (空)viewWillDisappear:(BOOL)動畫{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
[super viewWillDisappear:animated];
}
爲什麼不直接創建UIViewController的子類? – nduplessis 2010-12-06 08:17:43