Uinavigationcontroller + Uiscrollview combination, view size setting Quest (i)

Source: Internet
Author: User

Uinavigationcontroller and Uiscrollview are some of the main interactive elements under iOS, but when I match them together, the scrolling area of Uiscrollview is very strange. I hope uiscrollview horizontal can be page, portrait and its frame, such as high non-scrolling, but the strange is: 1, I put Uiscrollview contentsize set to the same frame height, but the result is that he can always scroll up and down a small segment. 2, I create a sub-view in Uiscrollview's (0, 0) position, and the runtime always goes down by dozens of pixels.

My program was originally written like this: Create Navigationcontroller (left) in story board, and use the default root View Controller (middle), which is a tableviewcontroller. Add a new Viewcontroller (right) and associate the Tableviewcell click action to the new Viewcontroller, and change this viewcontroller rootview to Uiscrollview, Story board is as follows:

Add the following code to the new Viewcontroller viewdidload:

  @interface   Viewcontroller ()  //  Modify the view to Uiscrollview and create a outlet variable for it  @property (strong, Nonatomic) Iboutlet uiscrollview *scrollview;   @end      -(void   //  set to page turn mode and set Contentsize to frame twice times width     self.scrollView.pagingEnabled = YES;    CGRect rect  = Self.scrollView.frame;    Rect.size.width  *= ; Self.scrollView.contentSize  = Rect.size;}  

The ScrollView are as follows, and you can see that when I drag, there are scroll bars both horizontally and vertically. Horizontal can be understood, vertical why can also scroll it:

To confirm the boundaries of the ScrollView content, I added two sub-view to it and set it to a red and blue background, respectively:

- (void) viewdidload {[Super viewdidload]; Self.scrollView.pagingEnabled=YES; CGRect rect=Self.scrollView.frame; Rect.size.width*=2; Self.scrollView.contentSize=rect.size; //Add a child view of the red and blue backgrounds, arranged horizontallyCGRect Rtviewa =Self.scrollView.bounds; UIView*viewa =[[UIView Alloc]initwithframe:rtviewa]; Viewa.backgroundcolor=[Uicolor Redcolor];        [Self.scrollview Addsubview:viewa]; CGRect RTVIEWB=Self.scrollView.bounds; Rtviewb.origin.x=RtViewA.size.width; UIView*VIEWB =[[UIView ALLOC]INITWITHFRAME:RTVIEWB]; Viewb.backgroundcolor=[Uicolor Bluecolor]; [Self.scrollview ADDSUBVIEW:VIEWB];}

The resulting effect is this:

Found entering the ScrollView, the initial state seems to be correct, but a little drag to find the exception: The red view is easy to be bounced to the top, the bottom of the Navigationbar, and after the rebound, there is no blank, this indicates that the size of Viewa is not correct. The size of the Viewa is more than the ScrollView created, if the size of the Viewa is large, that is not to show that the size of the ScrollView is also too large?

So I opened the debug View Hierarchy, like, light blue is ScrollView, red is Viewa,

Print out the information for both:

Printing Description of $3:<uiscrollview:0x7fe7bb827200; frame = (0 0;375 667); AutoResize = w+h; Gesturerecognizers = <nsarray:0x7fe7b9f42f60>; Layer = <calayer:0x7fe7b9f404e0>; Contentoffset: {0, - -}; Contentsize: { -,667}>Printing Description of $4:<uiview:0x7fe7b9f28000; frame = (0 0;375 667); Layer = <calayer:0x7fe7b9f4a050>>

From log to see Viewa and scrollview such as high, no problem. However, it is clear from the debug View hierachy that the upper-left corner of the ScrollView is in the upper left-hand corner of the window, superimposed on the bottom of the Navigationbar, rather than under Navigationbar!

Is my view arranged in a nonstandard way? I wonder if Navigationbar belonged to Rootview? So if you want to not be navigationbar, you should set Rootview to normal view and create a ScrollView sub-view underneath it. That means let Navigationbar and scrollview up and down in Rootview. Next I will continue to do experiments to verify.

Uinavigationcontroller + Uiscrollview combination, view size setting Quest (i)

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.