/ Published in: iPhone
when changing orientation the scrollview has extra content size
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#define SCROLLVIEW_CONTENT_HEIGHT_PORTRAIT 800 #define SCROLLVIEW_CONTENT_WIDTH_PORTRAIT 320 #define SCROLLVIEW_CONTENT_HEIGHT_LANDSCAPE 670 #define SCROLLVIEW_CONTENT_WIDTH_LANDSCAPE 480 ........ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; name: UIKeyboardDidShowNotification object:nil]; name: UIKeyboardDidHideNotification object:nil]; m_scrollView.contentSize = CGSizeMake(SCROLLVIEW_CONTENT_WIDTH_PORTRAIT, SCROLLVIEW_CONTENT_HEIGHT_PORTRAIT); displayKeyboard = NO; } - (void)viewWillDisappear:(BOOL)animated { } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } { if (displayKeyboard) { return; } if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) { m_scrollView.frame = CGRectMake(0, 0, SCROLLVIEW_CONTENT_WIDTH_LANDSCAPE, 140); } else { m_scrollView.frame = CGRectMake(0, 0, SCROLLVIEW_CONTENT_WIDTH_PORTRAIT, 240); } CGRect textFieldRect = [m_activeField frame]; textFieldRect.origin.y += 10; [m_scrollView scrollRectToVisible:textFieldRect animated:YES]; displayKeyboard = YES; } { if (!displayKeyboard) { return; } if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) { m_scrollView.frame = CGRectMake(0, 0, SCROLLVIEW_CONTENT_WIDTH_LANDSCAPE, 300); m_scrollView.contentSize = CGSizeMake(SCROLLVIEW_CONTENT_WIDTH_LANDSCAPE, SCROLLVIEW_CONTENT_HEIGHT_LANDSCAPE); } else { m_scrollView.frame = CGRectMake(0, 0, SCROLLVIEW_CONTENT_WIDTH_PORTRAIT, 460); m_scrollView.contentSize = CGSizeMake(SCROLLVIEW_CONTENT_WIDTH_PORTRAIT, SCROLLVIEW_CONTENT_HEIGHT_PORTRAIT); } displayKeyboard = NO; }