iphone - UIScrollView添加了 subview 但无法滑动到它们

标签 iphone objective-c ios

- (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/

相关文章:

iphone - runloop 可以分配给 rununtildate 的最大值是多少?

iphone - xmppframework (iOS) 和配置身份验证类型

objective-c - 如何将字符串部分与 Objective-C 中的 NSArray 值进行匹配

objective-c - 移除 applicationDidEnterBackground 中的 uialertview

ios - Swift:如何以正确的方式将 [[String]] 连接到 [String]?

ios - DateFormatter 返回时区的意外日期

iphone - 我如何在 iOS 上制作爆炸动画?

ios - 如何向人们发送我的应用测试版?

iphone - 如何使用 Titanium 为 iPhone 应用程序创建星级评级控件?

ios - 应用内购买数量限制问题