Reputation: 909
I have the following situation: I have a UIViewController
, which has a UIScrollView
inside of it. The content of this scroll view, is a "canvas", where things get drawn on using CoreGraphics
. The image this canvas will ultimately show is similar to a tree structure, all done programatically. My problem is: I want to be able to increase the canvas size, so that the old image is on the middle of the new allocated canvas size, and this new canvas size should then be the scroll view content, for things to get drawn around at the new allocated border and panned with.
So far this is what I have:
In the canvas class:
if (totalWidthOccupiedByChildren > totalSpaceAvailableDad) {
CGSize newSize = CGSizeMake(self.frame.size.width*1.1, self.frame.size.height*1.1);
self.frame = CGRectMake(0, 0, newSize.width, newSize.height);
[self.delegate shouldIncreaseScrollView];
}
In the ViewController class:
-(void)shouldIncreaseScrollView{
self.scrollView.contentSize = CGSizeMake(paintV.frame.size.width, paintV.frame.size.height);
}
This works "ok", and both the canvas and scroll view are increased and now allow panning, but the old image shows at the upper left corner, and I need to center it. Any idea how?
Upvotes: 1
Views: 168
Reputation: 909
What worked for me in the end was refactoring my architechture a bit, to that I had the variables I needed. But the property which I ended up setting is scrollView.contentOffset
, just for future reference :)
Upvotes: 1
Reputation: 525
What you can do is, putting all the stuff inside a UIView and adding that UIView to UIScrollView. You need to ensure that UIView.center equals UIScrollView.center. Also, you will need to adjust UIView frame size along with UIScrollView size.
Upvotes: 0