IOS滚动库
我在我的应用程序中创建了此幻灯片库:IOS滚动库,ios,objective-c,Ios,Objective C,我在我的应用程序中创建了此幻灯片库: UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(photoTap:)]; tap.numberOfTapsRequired = 1; int pageCount = 3; UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectM
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(photoTap:)];
tap.numberOfTapsRequired = 1;
int pageCount = 3;
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,
0,
360,
200)];
scrollView.backgroundColor = [UIColor clearColor];
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(pageCount*scrollView.bounds.size.width ,
scrollView.bounds.size.height);
[scrollView addGestureRecognizer:tap];
CGRect viewsize = scrollView.bounds;
UIImageView *image = [[UIImageView alloc]initWithFrame:viewsize];
[image setImage: [UIImage imageNamed:@"01.png"]];
image.userInteractionEnabled = YES;
[scrollView addSubview:image];
viewsize = CGRectOffset(viewsize, scrollView.bounds.size.width, 0);
UIImageView *image2 = [[UIImageView alloc]initWithFrame:viewsize];
[image2 setImage: [UIImage imageNamed:@"02.png"]];
image2.userInteractionEnabled = YES;
[scrollView addSubview:image2];
- (void)photoTap:(UITapGestureRecognizer *) gestureRecognizer{
}
如何检测滚动视图中点击的照片?
我曾尝试将手势识别器添加到图像中,但只有最后一个有效。
有什么建议吗?谢谢您可以将手势识别器添加到scrollview,在检测到点击后,通过将点击的坐标添加到内容偏移来检测其在UIScrollView内容上的位置。有了这个坐标后,我认为检测图像不是问题。手势识别器已经添加到scrollview中。