我对此感到疯狂!我有以下代码,它不会向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];
}
答案 0 :(得分:1)
没有什么东西在跳我。
以下是一些要检查的事项:
答案 1 :(得分: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);
}