English 中文(简体)
Get the identity of the image loaded at the centre of the screen currently?
原标题:

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?

最佳回答
  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
问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签