嗨,我是 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 语句中做什么来确定用户在第一张照片上?谢谢!