views:

189

answers:

1

Hi.

I have a problem with a UIScrollView. I set its frame.size, contentSize (bigger then frame), but I still can't scroll. My program has sctucrure like this: MainMenuViewController -> ScrollBarController -> UIScrollView

This is a part of MainMenuViewController's method viewDidLoad

ScrollBarController *imgScrollBarCtrl = [[ScrollBarController alloc] init];
// set images folder
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagesFolder = [documentsDirectory stringByAppendingPathComponent:@"SavedImages"];

// set scroll bar frame size
imgScrollBarCtrl.view.frame = CGRectMake(0.0, 0.0, 1024.0, 128.0);
[imgScrollBarCtrl setImagesFolder:imagesFolder];

// method adds subviews UIImageView to the scroll bar 
// and set view's contentSize according thumbnails number
[imgScrollBarCtrl recalculateThumbnailsBounds];

[topPanel addSubview:imgScrollBarCtrl.view];
[imgScrollBarCtrl release];

There is method loadView from ScrollBarController class:

- (void)loadView {

    UIScrollView *aScrollView = [[UIScrollView alloc] init];

    aScrollView.scrollEnabled = YES;

    self.view = aScrollView;

    [aScrollView release];
}

I set contentSize of my scrollView in recalculateThumbnailsBounds of ScrollBarController. It was set correctly (1620.0, 128.0), but scrolling doesnt't work. I've tried to set contentSize in MenuViewController by adding: ((UIScrollView *)imgScrollBarCtrl.view).contentSize(2000.0, 128.0); but it doesn't work as well.

I do NSLog(...) after setting contentSize and print frame size and contentSize to the console - they are set properly freme.size = 1028.0,128.0, contentSize = 1620.0,128.0.

I've checked methods - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event in both controllers - MainMenuController and ScrollBarController. Only main controller fires this method. ScrollBarController never receives touches events... probably that is an issue...

Does anyone have an idea what could be wrong? Cheers!

A: 
[[UIScrollView alloc] initWithFrame:(CGRect)frame]

All the UIView descendant are using the scheme.

Also, your code snippet is not really clear on what you are trying to achieve so you might have other problems in your code.

You should try to start off setting a contentSize in the - (void)loadView method first and see if you get the proper behavior.

Pier-Olivier Thibault
I've tried that already. Tried again after your recommendation. I have same thing - scroll view and subviews layout is proper but scroll view doesn't scroll. What methods exactly do you need to have a better picture? I just thought that this methods are enough. Other methods more to calculate frames for `UIImageView` views and add them to the scroll view.
OgreSwamp