I am getting a strange interface error with my UIScrollView and I cannot figure out how to solve it. I wrote only one line of code (shown below), and this empty project setup is easily reproducible !
Installation:
I have a UIScrollView that contains a UISegmentedControl (since the control segments are loaded dynamically, it can exceed the width of the screen, and scrollView should scroll the horizontal control horizontally, the scroll height is the same as UISegmentedControl). The ViewController containing this is embedded in the tabBar (or the navigation bar, which also displays an error). It's all about using Auto-Layout.
Error:
When I scroll the SegmentedControl to some degree to the right, and then switch the viewController by clicking on the other tabBarController tab, the offset of the contents of the segmented control is shifted when I switch back to the original view manager. When I try to scroll to the very left of the scroll, this will not allow me. When you switch tabs a couple of times, it is fixed again, and I can do it.
What I did (can you reproduce this?):
- Create an empty iOS project with one view.
- Paste the already provided viewController into the tabbar.
- Place scrollView at the top of the view, which matches the screen from left to right.
- Place the UISegmentedControl in the top scroll corner and drag the scroll according to the height of the segmented controls.
- Change the width of the segment control so that xcode adds a width limit. in a segmented control width constraint, the ratio of the width constraint to greater than or equal to is changed
- create output for segmented control
in viewDidload add this code
[self.segmentedControl insertSegmentWithTitle:@"A really long title so it you have to scroll to see it" atIndex: 0 animated: NO];
Create an empty view manager and add it as the second viewController for the tabbarController.
This is what my storyboard looks like:

Now run the project, scroll the segmented control to it to the right, as far as possible. Switch the tab and go back and please tell me how your scroll mode behaves - and WHY.
My guess: is this possibly due to auto-layout? I can not understand that.
I tried to fix this by setting scrollView contentSize to viewDidAppear or changing the offset of the scrollView content in viewDidAppear or changing the frames, their combination and what not ...
Additional question:
Is there no need to set the scrollViews contentSize property? Why does it automatically scroll content?
Mario source share