views:

20

answers:

1

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?

A: 
  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
Alex Reynolds
Problem is I know which tile is there but want to get its name,ie for eg,http://stage.discoveritalia.it/tiles/10/6028/5078.png. I want to take that into a string, then parse it and get the last two integer values. And depending on it I should load the next 25 images surrounding them with the one i got at the centre of the contentSize. All this for doing infinte UIScrollView.
wolverine
Hey, i figured it out. Just store all the urls or more specifically the 2 values in the url that I want in an array. As per ur formula I will get an x and y. x*5+y will give me the index of that array, which will give me the value. Thanks a lot.
wolverine