首页 文章

将imageView加载到scrollView的问题

提问于
浏览
0

我是Objective-c的新用户 . 我有一个问题是将imageview加载到scrollview .

我使用界面构建器将滚动视图添加到视图上 . 然后我尝试通过代码在scrollview上添加一个imageview .

UIImage * image = [[[UIImage alloc] init] autorelease]; image = [UIIamge imageNamed:@“cover.jpg”];

imageView = [[[UIImageView alloc] init] autorelease]; imageVIew.frame = CGRectMake(50.0,40.0,200.0,200.0); imageView.image = image;

[scorllView addSubview:imageView];

然后我将另一个imageView添加到ScrollView上,位置为(50.0,1000.0),长度= 200,宽度= 200(ipad的屏幕为786 * 1004),照片可以出现在屏幕上 . 第二张照片不完整,我尝试滚动屏幕,但我无法滚动它 .

谢谢 .

2 回答

  • 0

    首先,你只需要

    UIImage * image = [UIImage imageNamed:@ "cover.jpg"];
    除了"alloc"之外,创建它的实例的类方法(imageNamed:here)将创建一个自动释放的对象 .

    [UIImage imageNamed:@ "cover.jpg"]在概念上与...相同
    [[UIImage alloc] initWithFileContents:@ "cover.jpg"] autorelease] //注意,分配一次,释放一次 .
    (内部可能不一样,imageNamed:缓存图像initWithFileContents:可能不会)

    要滚动scrollView,您需要确保许多事项 .

    其中一个是确保你的scrollView 's contentSize is bigger than your scrollView'的帧大小 .
    尝试设置你的scrollView.contentSize = CGSizeMake(someBigValue,someBigValue);

    scrollView内的内容在scrollView中滚动 . 因此,您的内容应该大于scrollView的帧大小才能滚动 .

  • 0

    你必须增加contentinset或UIScrollview使其可滚动,你可以增加底部,

    scorllView.contentInset = UIEdgeInsetsMake(0, 0, 680, 0);
    

    或根据需要增加

相关问题