【问题标题】:Adding UIImageViews to UIScrollView将 UIImageViews 添加到 UIScrollView
【发布时间】:2010-09-23 10:21:37
【问题描述】:

我目前正在研究将多个UIImageView 添加到单个UIScrollView 的方法。 UIScrollView 将是UIImageViews 中任何一个的大小的 1.5 倍。我想创建一个滚动效果来浏览 iPad 应用程序中的一些小图像。有谁知道如何做到这一点?

【问题讨论】:

    标签: iphone objective-c cocoa-touch


    【解决方案1】:
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(/*FRAME*/)]; // this makes the scroll view - set the frame as the size you want to SHOW on the screen
    [scrollView setContentSize:CGSizeMake(/*SIZE OF THE CONTENT*/)]; // if you set it to larger than the frame the overflow will be hidden and the view will scroll
    
    /* you can do this bit as many times as you want... make sure you set each image at a different origin */
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"/*IMAGE*/"]]; // this makes the image view
    [imageView setFrame:CGRectMake(/*SET AS 2/3 THE SIZE OF scrollView AND EACH IMAGE NEXT TO THE LAST*/)]; // this makes the image view display where you want it and at the right size
    [scrollView addSubview:imageView]; // this adds the image to the scrollview
    /* end adding image */
    
    [self.view addSubview:scrollView];
    

    【讨论】:

    • 好的,伙计!会试一试的!
    • 很好的解释谢谢队友。是否有强制滚动条始终可见?
    • 或者一种使它具有动画效果的方法或其他方式,以便用户知道他们可以滚动
    • 很好的解释!还记得在将它们添加为子视图后释放分配的视图。如果您想学习如何实现分页(Snaps to imageview)和页面指示器,如何在视图之外发布图像,我建议您查看我给您的第二个链接。如果您希望能够放大图像,请使用第一个链接。
    • 是的,抱歉——我来自 php 背景,主要问题是内存管理。最好的方法(我发现)是在你的元素周围放置 [[...] autorelease] - 这样你就不必记住释放它们(直到你得到 EXC_BAD_ACCESS 和各种...... :p)
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 2023-03-04
    • 2015-06-29
    • 2017-12-19
    • 2023-03-28
    相关资源
    最近更新 更多