Ios7 navigation controller switching affects UIScrollView Layout
In iOS 7, if a UIViewController's self. the first sub-view of the view is UIScollView. When the UIViewController is pushed or initWithRootController becomes the Controller Controlled by UINavigationController, all sub-views of the UIScollView of the view of the UIViewController will be moved down to 64px. The premise for this 64 PX move down is that the navigationBar and statusBar are not hidden. For statusBar, the default Height is 20px, and for navigatiBar, the default Height is 44px. The following is an example: Do not use the navigation interface to jump 1. in AppDelegate. in the m file: Obj-c code favorites code-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen] bounds]; self. window. backgroundColor = [UIColor whiteColor]; // The code added to the following two actions is ViewController * rootViewController = [[ViewController alloc] init]; [self. window setRootV IewController: 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 setBackgroundC Olor: [UIColor blueColor]; [scrollView addSubview: view]; [self. view addSubview: scrollView];} 3. results After running: scrollView is not affected in the case of a wKioL1M02bjAygEmAABp-pZVp3I608.jpg. 4. now using UINavigationController will start AppDelegate. the two lines added by m are changed to: Obj-c code favorites code ViewController * rootViewController = [[ViewController alloc] init]; UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController: rootViewController]; [self. window setRootViewController: navController]; 5. run the program again: wKiom1M02uuD8SEiAAB48M0Pmhc504.jpg. If the result is displayed, the position of the child view whose background color is blue is automatically moved down. The moving distance is exactly 64.0px. Solution: first, add a line of code in the init method of ViewController: Obj-c code to add code self to favorites. automaticallyAdjustsScrollViewInsets = NO; Type 2: Make UIScrollView the first subview of ViewController. Specific Operation: Modify the viewDidLoad Method to the following: Obj-c code favorites code-(void) viewDidLoad {[super viewDidLoad]; UIView * firstSubView = [[UIView alloc] initWithFrame: self. view. bounds]; [self. view addSubview: firstSubView]; UIScrollView * scrollView = [[financialloc] 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];} Category 3: Move the sub-view of UIScorllView up to 64.0px. Modify 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]; [s CrollView addSubview: view]; [self. view addSubview: scrollView]; 4: set transparent attributes of the navigation bar. Self. navigationController. navigationBar. translucent = YES changes the transparency of the navigation bar, which can be adjusted according to your actual needs.