#ifdef __IPHONE_5_0 float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if (version >= 5.0) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillChangeFrameNotification object:nil]; } #endif
5.0後版本可使用app
#pragma mark - #pragma mark Responding to keyboard events - (void)keyboardWillShow:(NSNotification *)notification { /* Reduce the size of the text view so that it's not obscured by the keyboard. Animate the resize so that it's in sync with the appearance of the keyboard. */ NSDictionary *userInfo = [notification userInfo]; // Get the origin of the keyboard when it's displayed. NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; // Get the top of the keyboard as the y coordinate of its origin in self's view's coordinate system. The bottom of the text view's frame should align with the top of the keyboard's final position. CGRect keyboardRect = [aValue CGRectValue]; if( keyboardRect.size.height <= 216 ) { _CommentPostView.frame = CGRectMake(0, 505-216-46, 320, 46); } else { _CommentPostView.frame = CGRectMake(0, 505-252-46, 320, 46); } } #pragma mark UITextField delegate end---------------------