获取当前屏幕中央加载的图片的标识?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CGPoint
(取决于方向)x
和y
值除以1280 / 5
code> 并添加((1280 / 5) / 2)
以确定中心将重叠的图块ij
索引,没有UIScrollView
偏移CGPoint
at the center of the screen (depending on orientation)x
andy
values by1280 / 5
and add((1280 / 5) / 2)
to determine the tilei-j
indices that the center would overlap, with noUIScrollView
offset