垂直滚动

时间:2010-09-17 08:39:28

标签: iphone

我正在使用以下代码在scrooll视图上滚动图像,

StoryViewScroller = [[[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 79.0f, 320.0f, 262)] autorelease];
StoryViewScroller.contentSize = CGSizeMake(NPAGES * 320.0f, StoryViewScroller.frame.size.height);
StoryViewScroller.pagingEnabled = YES;
StoryViewScroller.delegate = self;
StoryViewScroller.showsHorizontalScrollIndicator = NO;
StoryViewScroller.scrollsToTop = YES;
// Load in all the pages
for (i = 0; i < NPAGES; i++)
{
    NSString *filename = [NSString stringWithFormat:@"%d.jpg", i+1];
    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:filename]];
    iv.frame = CGRectMake(i * 320.0f, 0.0f, 320.0f, 262);
    [StoryViewScroller addSubview:iv];
    NSLog(@"I is :: %d" ,i);
    [iv release];
}

[self.view addSubview:StoryViewScroller];

这样就可以从左到右滚动视图,反之亦然。我应该更改为从上到下滚动视图,反之亦然。

sugggestions

问候

1 个答案:

答案 0 :(得分:1)

要启用垂直滚动,请为contentSize设置适当的高度,例如

StoryViewScroller.contentSize = CGSizeMake(320.0f, NPAGES*StoryViewScroller.frame.size.height);