2012-12-06 35 views

回答

2

這是用U IKeyboardWillShowNotificationUIKeyboardDidShowNotificationUIKeyboardWillHideNotificationUIKeyboardDidHideNotification通知做推鍵盤迴落。 然後,當你處理通知調整框架的高度:

例如:

- (void) keyboardWillShow:(NSNotification *)aNotification{ 

    NSDictionary* info = [aNotification userInfo]; 
    NSTimeInterval duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; 

    NSValue* aValue = [info objectForKey:UIKeyboardFrameBeginUserInfoKey]; 
    CGFloat keyboardHeight = [aValue CGRectValue].size.height; 

    self.keyboardVissible = YES; 

    [UIView animateWithDuration:duration animations:^{ 
     CGRect frame = self.contentView.frame; 
     frame.size.height -= keyboardHeight; 
     self.contentView.frame = frame; 
    }]; 
} 

您需要註冊接收通知,您應該只聽鍵盤通知時,視圖

- (void) viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; 
} 

- (void) viewDidDisappear:(BOOL)animated { 
    [super viewDidDisappear:animated]; 

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; 
} 
+0

是什麼fetchedResultsController:是,如果你做的viewDidLoad可見,奇怪的事情會發生? – user1372829

+0

抱歉,'fetchedResultsController'是一個複製過去錯誤。 – rckoenes

+0

很酷我會試試看謝謝:) :) – user1372829