- (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,当我尝试从左向右拉动 ScrollView 时,它没有移动,我添加了4个 subview ,但为什么我无法查看它们?
最佳答案
你应该设置scrollView的内容大小
[self. scrollerView setContentSize:CGSizeMake(320, 1000)];
给出你的宽度和高度。
关于iphone - UIScrollView添加了 subview 但无法滑动到它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10211242/