IPhone UIScrollView ContentSize has extra height when rotated / converted to landscape

Execution of any iPhone developer, the application works quite well. However, I have a UIScrollView with autoresistant content and contentSize, which works quite well, except when I turn to landscape view, at the scroll height it always has about 100 pixels. I don’t want users to be able to scroll through content lately.

Has anyone else had this problem or was aware of a fix?

thanks in advance,

Michael

+4
source share
2 answers

I had the same problem. In my case, I was iterating over a UIScrollView, trying to dynamically calculate its contentSize. Making my way through subviews, I found two mysterious imageViews among subviews (not added by me) that together added exactly 100 pixels. It turns out that these two images are actually scroll indicators that are automatically added to the scroll list.

My solution was to create a container view class, call it a ContainerView, and in it I created a scroll.

Inside this ContainerView, I override the addSubview and willRemoveSubview methods, for example:

- (void)addSubview:(UIView *)view { [_addedSubviews addObject:view]; [_scrollView addSubview:view]; } - (void)willRemoveSubview:(UIView *)subview { [_addedSubviews removeObject:subview]; [_scrollView willRemoveSubview:subview]; } 

Now you can add a method to calculate the size. This time we will move on to an array called _addedSubviews, not subviews scrollviews, because we know that the views inside _addedSubviews are just the ones that we added. And because of this, we will avoid the loop using the scroll indicators and something else :-)

And finally, just cycle through and figure out.

 - (CGSize)desiredContentSize { for(UIView *mySubviews in _addedSubviews) { // Calculate size } // Return size } 
+4
source

Zath has an interesting solution. I came across a similar one.

I want to say that you do not update your content content after switching to landscape, but the contentSize should be the same.

Ironically, I now had the opposite problem. However, after learning about supervisors, autoresizesSubviews should be set to yes, and to ensure that all 4 supervisors have the same resizing property, it finally saves a β€œbuffer space”.

A lot of starts after tuning and in the end you get what you want if you don't want the top y to stay in the same place when it is greater than 0.

0
source

Source: https://habr.com/ru/post/1307748/


All Articles