안녕 키보드를 들어 올리기 위해 다음과 같은 방법을 사용하고 있습니다. 사용할 수있는 뷰 컨트롤러가 많지만 위임을 시도한 적이 없습니다. 나는 확실히 이것을 모든 뷰 컨트롤러에 삽입하고 싶지 않습니다. 어떤 아이디어 아이폰 위임
- (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