views:

1150

answers:

2

In my app I have some logic that changes the UIScrollView's contentSize dynamically. The problem I'm running into is that when I change the contentSize it sets the contentOffset to CGPointZero or something like that.

I guess you can't set contentSize to be in the middle of the UIScrollView. Any ideas on how to get this to work?

In other words I want to change the contentSize of my UIScrollView half way and keep its contentOffset.

thanks in advance,

fbr

A: 

As you've already seen, you can't do this by changing contentSize, but you can fake it by changing the contentOffset and moving your subviews around. An example of this in the DTInfiniteGridView class of Daniel Tull's DTKit library.

Nathan de Vries
I'm not familiar with this library. Could you tell me where in the code he is faking it contentSize with contentOffset.This is what I'm trying to do. I'm developing a data table where you can see data in columns and rows just like an excel spreadsheet. The reason why I want to set the contentSize dynamically is to constrain the user to vertical and horizontal scrolling only. So if I detect a Vertical scroll in the UIScrollView I set the contentSize where the width is equal to the width of the UIScrollView's frame and I maintain the height.
ForeignerBR
Why can't you use UIScrollView's directionalLockEnabled?
David Kanarek
A: 

I don't know about which is the method will used,

- (void)viewDidLoad {
    [super viewDidLoad];
    srcv.contentSize = ?;
}

Here what will come and replace with "?" to scroll the simulator