CHAPTER 6 EXERCISE SOLUTIONS
Answer to Question 1
First, handle the Did End on Exit event (or implement the textFieldShouldReturn: method in the View Controller). Then call the resignFirstResponder method of the UITextField outlet to release its first-responder status.
Answer to Question 2
Register for the notifications UIKeyboardDidShowNotification and UIKeyboardDidHideNotification.
Answer to Question 3
NSDictionary* info = [notification userInfo]; //---obtain the size of the keyboard--- NSValue *aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey]; CGRect keyboardRect = [self.view convertRect:[aValue CGRectValue] fromView:nil]; NSLog(@“%f”, keyboardRect.size.height);
Answer to Question 4
Use the UIScrollView to contain views so that the user can scroll through them. Then, set the new size of the scroll view:
- (void)viewDidLoad { //---set this to the screen size--- scrollView.frame = CGRectMake(0, 0, 320, 460); //---set this to the final size of the scroll view--- [scrollView setContentSize:CGSizeMake(320, 713)]; [super viewDidLoad]; }
Get Beginning iOS 5 Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.