Resizing UIView - expanding the top

I have a UIView inside a UIScrollView that I want to change.

I can easily increase the height:

CGRect frame = self.drawinView.frame;
frame.size.height += 100;
self.drawinView.frame = frame;
self.drawinScrollView.contentSize = CGSizeMake(frame.size.width, frame.size.height);

      

And all is well.

The above code will create a new view area at the bottom of the view that I can fill.

Now when I resize the view, I only want to redraw the new part of the newly created view. I don't want to redraw the whole view.

But! I ran into difficulties when I need to expand the top of the view.

Performance:

CGRect frame = self.drawinView.frame;
frame.origin.y -= 100;
self.drawinView.frame = frame;
self.drawinScrollView.contentSize = CGSizeMake(500, 600);

      

does not work.

How can I do this without redrawing the whole view?

+2


a source to share


2 answers


You can set the size of the content to any large amount you want, but you can never scroll further left or up than the top left corner by 0.0. If you have a view with y to -100, it won't let you scroll to 100px above 0.

Instead, you need to leave it where it is and instead set it contentOffset

to +100 vertically.

If, for example, you want to resize the view 100px up, you would do the following:



CGRect frame = self.drawinView.frame;
frame.size.height += 100;
self.drawinView.frame = frame;
self.drawinScrollView.contentSize = CGSizeMake(frame.size.width, frame.size.height);
self.drawinScrollView.contentOffset = CGPointMake(0,100);

      

How should you manually communicate drawinView

that you want to block the content at the bottom of the view, not the top.

+1


a source


In the above code, you are only changing the start of the view. Not the size.



0


a source







All Articles