Posted By

devb0yax on 06/28/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

leachypeachy
bobbym245


keyboard


 / Published in: iPhone
 

  1. #define SCROLLVIEW_CONTENT_HEIGHT_PORTRAIT 610
  2. #define SCROLLVIEW_CONTENT_WIDTH_PORTRAIT 320
  3. #define SCROLLVIEW_CONTENT_HEIGHT_LANDSCAPE 500
  4. #define SCROLLVIEW_CONTENT_WIDTH_LANDSCAPE 480
  5.  
  6. ....
  7.  
  8. - (void)viewWillAppear:(BOOL)animated
  9. {
  10. [super viewWillAppear:animated];
  11.  
  12. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:)
  13. name: UIKeyboardDidShowNotification object:nil];
  14. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:)
  15. name: UIKeyboardDidHideNotification object:nil];
  16.  
  17. m_scrollView.contentSize = CGSizeMake(SCROLLVIEW_CONTENT_WIDTH_PORTRAIT, SCROLLVIEW_CONTENT_HEIGHT_PORTRAIT);
  18. displayKeyboard = NO;
  19. }
  20.  
  21. - (void)viewWillDisappear:(BOOL)animated
  22. {
  23. [super viewWillDisappear:animated];
  24. [[NSNotificationCenter defaultCenter] removeObserver:self];
  25. }
  26.  
  27.  
  28. - (void)keyboardDidShow: (NSNotification *)notif
  29. {
  30. if (displayKeyboard) {
  31. return;
  32. }
  33.  
  34. if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
  35. self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)
  36. {
  37. m_scrollView.frame = CGRectMake(0, 0, SCROLLVIEW_CONTENT_WIDTH_LANDSCAPE, 140);
  38. }
  39. else
  40. {
  41. m_scrollView.frame = CGRectMake(0, 0, SCROLLVIEW_CONTENT_WIDTH_PORTRAIT, 240);
  42. }
  43.  
  44. CGRect textFieldRect = [m_activeField frame];
  45. textFieldRect.origin.y += 10;
  46. [m_scrollView scrollRectToVisible:textFieldRect animated:YES];
  47.  
  48. displayKeyboard = YES;
  49. }
  50.  
  51. - (void) keyboardDidHide: (NSNotification *)notif
  52. {
  53. if (!displayKeyboard) {
  54. return;
  55. }
  56.  
  57. if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
  58. self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)
  59. {
  60. m_scrollView.frame = CGRectMake(0, 0, SCROLLVIEW_CONTENT_WIDTH_LANDSCAPE, 300);
  61. m_scrollView.contentSize = CGSizeMake(SCROLLVIEW_CONTENT_WIDTH_LANDSCAPE, SCROLLVIEW_CONTENT_HEIGHT_LANDSCAPE);
  62. }
  63. else
  64. {
  65. m_scrollView.frame = CGRectMake(0, 0, SCROLLVIEW_CONTENT_WIDTH_PORTRAIT, 460);
  66. m_scrollView.contentSize = CGSizeMake(SCROLLVIEW_CONTENT_WIDTH_PORTRAIT, SCROLLVIEW_CONTENT_HEIGHT_PORTRAIT);
  67. }
  68.  
  69. displayKeyboard = NO;
  70. }

Report this snippet  

You need to login to post a comment.