IOS7 navigation controller switching affects Uiscrollview layout issues

Source: Internet
Author: User

In IOS 7, if the Self.view first child view of a uiviewcontroller is Uiscollview, and when this uiviewcontroller is push or initwithrootcontroller becomes   When Uinavigationcontroller controls a controller, all child views of this Uiviewcontroller view Uiscollview are moved down by 64PX. The premise of this move down 64px is that Navigationbar and StatusBar are not hidden. Because the default height for StatusBar is 20px, and the default height of Navigatibar is 44px. Here's an example: Jump 1 without using the navigation interface. In the APPDELEGATE.M file: Obj-c Code Collection Code-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (   Nsdictionary *) launchoptions {Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];                                 Self.window.backgroundColor = [Uicolor Whitecolor]; The following two behavior increases the code viewcontroller *rootviewcontroller = [[Viewcontroll   Er alloc] init];   [Self.window Setrootviewcontroller:rootviewcontroller];     [Self.window makekeyandvisible];  return YES; } 2. In VIEWCONTROLLER.M: Obj-c Code Collection Code-(void) Viewdidload {[Super ViewDidload];                                                           Uiscrollview *scrollview = [[Uiscrollview alloc] Initwithframe:cgrectmake (30.0,  64.0, 260.0, 300.0)];  [ScrollView Setbackgroundcolor:[uicolor Redcolor];  UIView *view = [[UIView alloc] initWithFrame:scrollView.bounds];  [View Setbackgroundcolor:[uicolor Bluecolor];  [ScrollView Addsubview:view];  [Self.view Addsubview:scrollview]; } 3. Results after operation: Wkiol1m02bjaygemaabp-pzvp3i608.jpg in this case, ScrollView is not affected. 4. Now use Uinavigationcontroller to modify the two lines of code that begin APPDELEGATE.M add: Obj-c Code Favorites Code Viewcontroller *rootviewcontroller = [Viewco   Ntroller alloc] init]; Uinavigationcontroller *navcontroller = [[Uinavigationcontroller alloc] Initwithrootviewc   Ontroller:rootviewcontroller];  [Self.window Setrootviewcontroller:navcontroller]; 5. Now run the program again: Wkiom1m02uud8seiaab48m0pmhc504.jpg as the result shows, the scrollView background color is blue and the sub-view position is automatically moved down. And this move down is just 64.0px away. Workaround: The first: Add one line of code to the Viewcontroller init method: Obj-c Code Collection Code Self.automAticallyadjustsscrollviewinsets = NO; The second kind: let Uiscrollview not be the first child view of the Viewcontroller view.  Action: Modify the Viewdidload method to the following: Obj-c Code collection Code-(void) viewdidload {[Super viewdidload];  UIView *firstsubview = [[UIView alloc] initWithFrame:self.view.bounds];  [Self.view Addsubview:firstsubview];                                                           Uiscrollview *scrollview = [[Uiscrollview alloc] Initwithframe:cgrectmake (30.0,  64.0, 260.0, 300.0)];  [ScrollView Setbackgroundcolor:[uicolor Redcolor];  UIView *view = [[UIView alloc] initWithFrame:scrollView.bounds];  [View Setbackgroundcolor:[uicolor Bluecolor];  [ScrollView Addsubview:view];  [Self.view Addsubview:scrollview]; The third way: Move the Uiscorllview's child view up by 64.0px.                                                           Modify the Viewdidload method: Obj-c Code Collection code Uiscrollview *scrollview = [[Uiscrollview alloc] Initwithframe:cgrectmake (30.0,  64.0, 260.0, 300.0)];  [ScrollView Setbackgroundcolor:[uicolor Redcolor]; CGRect viewframe = CGRectMake (0,-64.0, Cgrectgetwidth (Scrollview.frame),  Cgrectgetheight (Scrollview.frame));  UIView *view = [[UIView alloc] initwithframe:viewframe];  [View Setbackgroundcolor:[uicolor Bluecolor];  [ScrollView Addsubview:view];  [Self.view Addsubview:scrollview]; Fourth: Set the Transparency property of the navigation bar. Self.navigationController.navigationBar.translucent = yes changes the navigation bar transparency, also affects, this can adjust according to own actual demand.

IOS7 navigation controller switching affects Uiscrollview layout issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.