获取当前屏幕中央加载的图片的标识?

发布于 2024-08-14 03:00:43 字数 892 浏览 1 评论 0原文

我有一个 uiscrollview,内容大小为 1280*1280,并在其中加载了 25 个相同大小的图像。当我滚动并到达终点时,我想知道当前出现在屏幕中心的图像的身份。下面给出的是我用来将图像加载到滚动视图中的代码。我怎样才能弄清楚?

    for (i = 0; i < 5; i++) {
    if(j == 5)
    {
        tx = tx+1;
        x=x+256;
        ty = ty+5;
        y = y-1280;
    }
    for (j = 0; j < 5; j++) {
        imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://stage.discoveritalia.it/tiles/%d/%d/%d.png",zoom,tx,ty]]]]];
        frame = [imageView frame];
        frame.origin.x = x;
        frame.origin.y = y;
        [imageView setFrame:frame];
        [myScrollView addSubview:imageView];

        ty = ty-1;
        y = y+256;

        [imageArray insertObject:imageView atIndex:i*5+j];
        [imageView release];
     }
}

如果我能取回 URL,我的问题就会立即解决。有办法做到吗?

I have a uiscrollview with contentsize 1280*1280 and 25 images of equal size loaded in it. When i scroll and meet an end, I want to know the identity of the image which is currently present at the screen centre. Given below is the code that i used to load the images into the scrollView. How can i figure it out?

    for (i = 0; i < 5; i++) {
    if(j == 5)
    {
        tx = tx+1;
        x=x+256;
        ty = ty+5;
        y = y-1280;
    }
    for (j = 0; j < 5; j++) {
        imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://stage.discoveritalia.it/tiles/%d/%d/%d.png",zoom,tx,ty]]]]];
        frame = [imageView frame];
        frame.origin.x = x;
        frame.origin.y = y;
        [imageView setFrame:frame];
        [myScrollView addSubview:imageView];

        ty = ty-1;
        y = y+256;

        [imageArray insertObject:imageView atIndex:i*5+j];
        [imageView release];
     }
}

If I could get the URL back, it would solve my problem right away. Is there a way to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望笑 2024-08-21 03:00:43
  1. 计算屏幕中心的 CGPoint(取决于方向)
  2. xy 值除以 1280 / 5 code> 并添加 ((1280 / 5) / 2) 以确定中心将重叠的图块 ij 索引,没有 UIScrollView 偏移
  3. 现在添加当前滚动视图偏移量以确定中心实际重叠的图块
  1. Calculate the CGPoint at the center of the screen (depending on orientation)
  2. Divide the x and y values by 1280 / 5 and add ((1280 / 5) / 2) to determine the tile i-j indices that the center would overlap, with no UIScrollView offset
  3. Now add the current scroll view offset to determine which tile the center actually overlaps
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文