Changing Bounds of ScrollView shifts its location

126 views Asked by At

I have a scrollview. I need to add another view as a subview of this scrollview. The subviews frame is

(-13,20,200,90)

So while adding this view to scrollview the as subviews origin is negative some portion of the subview gets clipped.

As a solution i tried setting

[scrollView setClipToBounds:NO]

But this causes the contents in scrollview overflowing outside the frame of scrollview.

As a next step I tried changing the bounds of the scrollview like this

CGRect rect = container.scroller.bounds;
container.scroller.bounds = CGRectMake(rect.origin.x-205, rect.origin.y, rect.size.width+205, rect.size.height);

But this shifts the scrollviews position to right.

Basically I want to add an item outside the drawable areas of a UIScrollview without the subview getting clipped.

How can I achieve this in IOS?

2

There are 2 answers

0
EhTd On

Add the content in the self.view instead of the scrollView

0
Bohdan Orlov On

Width has to be increased as doubled x offset. So if you are moving bounds to left by 205, you have to increase a width by 410 to keep it centered.

original:
----===----
result:
---====----
intent:
---=====---