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.i开发者_开发技巧t/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?
- Calculate the
CGPoint
at the center of the screen (depending on orientation) - Divide the
x
andy
values by1280 / 5
and add((1280 / 5) / 2)
to determine the tilei-j
indices that the center would overlap, with noUIScrollView
offset - Now add the current scroll view offset to determine which tile the center actually overlaps
精彩评论