开发者

UIScrollView doesn't scroll

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
[imgScrollBarCtr开发者_JAVA百科l 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!


[[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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜