开发者

Resizing a UIView - expanding the top

I have a UIView inside of a UIScrollView that I want to resize.

I can increase the height easily by :

CGRect frame = self.drawinView.frame;
frame.size.height += 100;
self.drawinView.frame = fr开发者_开发技巧ame;
self.drawinScrollView.contentSize = CGSizeMake(frame.size.width, frame.size.height);

And all is good.

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

Now when I resize the view, I only want to be repainting the new portion of the view that has just been created. I dont want to have to repaint the whole view.

However! I have run into difficulty when I need to expand the top of the view.

Doing :

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 having to repaint the entire view?


You can set the content size to any large number you want, but you can never scroll further left or up than the top-left corner at 0,0. If you have a view with y at -100, it will not let you scroll to the 100px above 0.

Instead, you need to leave it where it is and instead set the contentOffset to +100 vertically.

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

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);

You would some how have to manually tell the drawinView that you want to lock the contents to the bottom of the view instead of the top.


In the above code you are only changing the origin of the view. Not it's size.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜