I opened a new project in Xcode 5, added a UITextField to the ViewController and linked its delegate.
This is my only code:
- (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myNotificationMethod:) name:UIKeyboardWillShowNotification object:nil]; } - (void)myNotificationMethod:(NSNotification*)notification { NSDictionary* keyboardInfo = [notification userInfo]; NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey]; CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue]; NSLog(@"Rect: %@",NSStringFromCGRect(keyboardFrameBeginRect)); }
Here is the log output:
Portraid:
Rect: {{0, 480}, {320, 216}}
Landscape:
Rect: {{-162, 0}, {162, 480}}
Edit:
Regarding textFieldDidBeginEditing called before name:UIKeyboardWillShowNotification , I really donβt understand why there is a difference if textField is in edit mode or not, but there are several ways to solve this problem.
in textFieldDidBeginEditing β Keep a link to the UIResponder and change the UIResponder to a temporary, irrelevant. in myNotificationMethod do what you want to do so that textField (which is not in \ first responder edit mode), when you are done, make it the main UIResponder .
Segev
source share