- (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个子视图,但为什么我无法查看它们?
答案 0 :(得分:1)
你应该设置scrollView的内容大小
[self. scrollerView setContentSize:CGSizeMake(320, 1000)];
给你的宽度和高度。
答案 1 :(得分:0)
在循环之后添加scrollerView.contentSize = CGSizeMake(yOrigin + self.view.frame.size.width, scrollerView.frame.size.height);
(尽管我对你的代码中为什么x-origin被称为yOrigin
感到有点困惑...)