【问题标题】:Best way for horizontal scrolling of image图像水平滚动的最佳方式
【发布时间】:2011-12-27 06:08:53
【问题描述】:

在 iphone sdk 中水平滚动图像的最佳方式是什么。图片必须从网络服务器获取,比如延迟加载?

请帮帮我。

【问题讨论】:

  • 您好@Sathish,如果您找到有关您的问题的任何解决方案,请在此处分享您的解决方案,因为它也可能对其他人有帮助,我也需要它,所以请分享!请。

标签: iphone image sdk horizontal-scrolling


【解决方案1】:

这是我的建议:

首先,为你的 UIScrollView 设置固定大小。

scroll.size = ... // your size

接下来,确定滚动的 contentSize 的宽度和高度。固定高度。宽度是可变的值。每次懒图加载成功后,调整宽度。

假设所有图像的高度相同。然后,每次加载图片时,代码是:

(在下面的代码中,我假设附加了新图像。根据您的情况,您可以根据需要进行适当的配置)

float oldScrollWith = scroll.contentSize.width
// creat new_image_view (UIImageView)
// configure it to display in the scroll
...                       
new_image_view.frame = CGRectMake(oldScrollWidth, 0, imageViewWidth, fixed_image_height)

// append the new view to the scroll
float newScrollWidth = oldScrollWidth + new_image_view.frame.size.width // re-calculate the width for the contentSize of scroll
scroll.contentSize = CGSizeMake(newScrollWidth, fixed_image_height);
[scroll addSubview:new_image_view];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    • 1970-01-01
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    • 2013-08-14
    • 1970-01-01
    相关资源
    最近更新 更多