你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS 獲取軟鍵盤高度

iOS 獲取軟鍵盤高度

編輯:IOS開發綜合

- (void)viewDidLoad{

[[NSNotificationCenterdefaultCenter] addObserver:self selector:@selector(keyboardDidShow:)

name:UIKeyboardDidShowNotification object:nil];

[[NSNotificationCenterdefaultCenter] addObserver:self selector:@selector(keyboardDidHide:)

name:UIKeyboardDidHideNotification object:nil];

}


- (void)keyboardDidShow:(NSNotification *)nsNotification {

NSDictionary *userInfo = [nsNotificationuserInfo];

_keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

[selfupdateTextViewSize];

}


- (void)keyboardDidHide:(NSNotification *)nsNotification {

_keyboardSize =CGSizeMake(0.0,0.0);

[selfupdateTextViewSize];

}


- (void)updateTextViewSize {

UIInterfaceOrientation orientation =

[UIApplication sharedApplication].statusBarOrientation;

CGFloat keyboardHeight = UIInterfaceOrientationIsLandscape(orientation) ? _keyboardSize.width

:_keyboardSize.height;

_textView.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - keyboardHeight);

}




  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved