1

我快疯了!我有以下代码,它没有向 UIScrollView 添加任何内容。在模拟器中渲染时的视图显示为完全白色。

- (void)viewDidLoad
{
    [super viewDidLoad];

    // add scroll view to the view 

      self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height - 200,self.view.frame.size.width,110)];

    self.scrollView.contentSize = CGSizeMake(400, 80);
    [self.scrollView setScrollEnabled:YES];
    [self.scrollView setPagingEnabled:YES];



    NSArray *imageNames = [NSArray arrayWithObjects:@"kidontrike_4.png",@"mockup_car2.png",@"mockup_car1.png", nil];

    for(NSString *imageName in imageNames) 
    {
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];

        imageView.frame = CGRectMake(0, 0, 100, 100);

        [self.scrollView addSubview:imageView];
    }


    [self.view addSubview:self.scrollView];


}

更新 1:

由于某种原因,即使添加带有背景颜色的视图似乎也不会出现。我只看到一个白屏。

@property (nonatomic,weak)  UIScrollView *scrollView; 

- (void)viewDidLoad
{
    [super viewDidLoad];

    // add scroll view to the view 

      self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];

    self.scrollView.contentSize = CGSizeMake(80, 80);
    [self.scrollView setScrollEnabled:YES];
    [self.scrollView setPagingEnabled:YES];


    UIView *someView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [someView setBackgroundColor:[UIColor greenColor]];

    [self.scrollView addSubview:someView];
    [self.view addSubview:self.scrollView];


}
4

2 回答 2

1

没有什么对我跳出来的。

这里有几件事要检查:

  • 如果您注销,滚动视图的最后一帧是什么?
  • 您将每个 imageView 添加到相同的确切位置,而不是偏移任何数量。
  • 您正在创建的图像可能不存在。也许尝试使用具有不同背景颜色的简单视图?
于 2012-05-01T19:50:59.677 回答
0
- (void)viewDidLoad
{
    [super viewDidLoad];

    // add scroll view to the view 

      self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height - 200,self.view.frame.size.width,110)];

    [self.view addSubview:self.scrollView];
    [self.scrollView setScrollEnabled:YES];
    [self.scrollView setPagingEnabled:YES];

    NSArray *imageNames = [NSArray arrayWithObjects:@"kidontrike_4.png",@"mockup_car2.png",@"mockup_car1.png", nil];
 UIImageView *imageView;
    for(NSString *imageName in imageNames) 
    {
       imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];

        imageView.frame = CGRectMake(0, 0, 100, 100);

        [self.scrollView addSubview:imageView];
    }

   self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, imageView.frame.size.height+imageView.frame.origin.y+100);


}
于 2015-01-09T06:17:04.903 回答