Uiscrollview pitfall-location change after uinavigationcontroller is pushed

Source: Internet
Author: User

I encountered a problem when using uiscrollview today. Record it. If this record is lucky to be searched by you, it may be helpful to you.

Today we have the following requirement:

Some information needs to be displayed on a page controlled by the navigation bar. More than 10 lines are currently available, so you may want to add more lines in the future. Therefore, you should consider using the scroll view here.

Because storyboard is used, a uiscrollview is dragged directly to the Controller view, and the frame is set to 320,504 ,.

Then start dragging the control to uiscrollview...

After the operation is complete, it is found that the control position in uiscrollview is incorrect, and the position of 64 is moved down, which is the height of the navigation bar and status bar...

After getting it from the left and right, it's still the same look...

So I asked them in the group. The answer is:

Generally, you do not need to drag controls. They are generally hand-written code and dynamically added...

Set the uiscrollview position to 0, 0, because when you push in, the view will be pressed down to the height of a navigation bar...

After some settings, the above position is OK, but the following scrolling is not coordinated: Because the Y value of uiscrollview is 0, it is to scroll down from the top of the screen ....

The result is still problematic. So I wrote the following sample code:

The example is very simple. A uinavigationcontroller navigation, with two lines under root, corresponding to two pages.

Two pages are stored in the same way.

A uiscrollview frame is 320,504

A lable is at 0, 0,

However, the position displayed after push changes: lable In the first page is moved down...

Problem:

In pages 1 and 2, uiscrollview is directly under the Controller view, that is, the first element in the Controller view is uiscrollview.

In this way, the nav will press a navigation bar down to the view (whether the height of the status bar is added I have not verified). So the position of the lable has changed...

Solution:

For example, in page 2, drag some space to the Controller view, so that uiscrollview is not the first element of the controller view.

Run the program, Go to page 2, and find that the location is what we want. The principle is not clear yet ..

I guess it may be because, if you know the reason, you can leave a message here.

Here, you can download the test project if necessary.

U Baidu online storage: after work, upload again tomorrow...

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.