-1
我該如何做到這一點whatsapp風格,其中點擊消息空間時,會從底部向上推鍵盤,以及向上推動工具欄。然後取消(即在後臺點擊)時,它會使用工具欄Whatsapp風格 - 鍵盤出現在工具欄下
我該如何做到這一點whatsapp風格,其中點擊消息空間時,會從底部向上推鍵盤,以及向上推動工具欄。然後取消(即在後臺點擊)時,它會使用工具欄Whatsapp風格 - 鍵盤出現在工具欄下
這是用U IKeyboardWillShowNotification
,UIKeyboardDidShowNotification
,UIKeyboardWillHideNotification
和UIKeyboardDidHideNotification
通知做推鍵盤迴落。 然後,當你處理通知調整框架的高度:
例如:
- (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];
}
是什麼fetchedResultsController:是,如果你做的
viewDidLoad
可見,奇怪的事情會發生? – user1372829抱歉,'fetchedResultsController'是一個複製過去錯誤。 – rckoenes
很酷我會試試看謝謝:) :) – user1372829