您好我是StackOverflow的新手,希望能够弄清楚我需要做什么才能引用我在数组中为滚动视图创建的单个图像。这是带有数组的滚动视图:
int PageCount = 2;
NSMutableArray *myArray =[[NSMutableArray alloc]initWithObjects:@"12-4.png",@"13-4.png",nil];
scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scroller.scrollEnabled=YES;
scroller.backgroundColor = [UIColor clearColor];
scroller.pagingEnabled = YES;
[self.view addSubview:scroller];
width=scroller.frame.size.width;
xPos=0;
for (int i=0; i<PageCount; i++)
{
ImgView = [[UIImageView alloc]initWithFrame:CGRectMake(xPos, 0, scroller.frame.size.width, scroller.frame.size.height)];
[ImgView setImage:[UIImage imageNamed:[myArray objectAtIndex:i]]];
[scroller addSubview:ImgView];
scroller.contentSize = CGSizeMake(width, 0);
width +=scroller.frame.size.width;
xPos +=scroller.frame.size.width;
}
然后使用if语句,我希望能够在滚动视图中确定我当前所处的图像,并且我尝试了这样:
if (ImgView.image == [UIImage imageNamed:[arrImageName objectAtIndex:0]])
{
NSLog(@"Yes");
}
尝试查看用户是否在objectAtIndex:0
的第一张图片上,但不幸的是,这不起作用。在if语句中我需要做什么才能确定用户是否在第一张照片上?谢谢!
答案 0 :(得分:0)
您应该根据页面大小和滚动视图的`contentOffset'进行计算。试图比较图像将更加困难,而且不太可靠。