0
- (void)viewDidLoad
{
MyData *data = [MyData SharedData];

scrollerView.pagingEnabled = YES;
scrollerView.bounces = YES;

int numberOfViews = [data.placePhotos count];
for (int i = 0; i < numberOfViews; i++) {

    CGFloat yOrigin = i * self.view.frame.size.width;
    UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
    awesomeView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 300 , 320)];

    NSString * photourl = [[data.placePhotos objectAtIndex:i] stringByReplacingOccurrencesOfString:@"150x75" withString:@"440x440"];

    [imageView setImageWithURL:[NSURL URLWithString:photourl]];
    [awesomeView addSubview:imageView];

    [scrollerView addSubview:awesomeView];
    awesomeView = nil;
    imageView =nil;
}

我在 .xib 文件中添加了 UIScrollView,当我尝试从左到右拉动滚动视图时它不会移动,我添加了 4 个子视图但为什么我无法查看它们?

4

2 回答 2

1

你应该设置滚动视图的内容大小

     [self. scrollerView setContentSize:CGSizeMake(320, 1000)];

给你的宽度和高度。

于 2012-04-18T14:16:15.877 回答
0

在循环之后添加(即使我对为什么在您的代码scrollerView.contentSize = CGSizeMake(yOrigin + self.view.frame.size.width, scrollerView.frame.size.height);中调用 x-origin 有点困惑......)yOrigin

于 2012-04-18T14:37:31.180 回答