gpt4 book ai didi

ios - 检测在 uiscrollView 中点击了哪个 UIImage

转载 作者:行者123 更新时间:2023-12-01 16:38:20 25 4
gpt4 key购买 nike

我有一个 UIScrollView装载了几个 UIImages ,对于这个例子,它加载了 5 UIImages 中的相同图片.如何检测 UIImages 中的哪一个?用户点击的?

这就是我正在使用的:

    _thumbnailScroll.delegate = self;

[_thumbnailScroll setBackgroundColor:[UIColor blueColor]];
[_thumbnailScroll setCanCancelContentTouches:NO];

_thumbnailScroll.indicatorStyle = UIScrollViewIndicatorStyleWhite;
_thumbnailScroll.clipsToBounds = NO;
_thumbnailScroll.scrollEnabled = YES;
_thumbnailScroll.pagingEnabled = YES;

NSUInteger nimages = 0;
NSInteger tot=0;
CGFloat cx = 0;
for (nimages = 0; nimages < 5 ; nimages++) {

UIImage *image = [UIImage imageWithContentsOfFile:[path stringByAppendingPathComponent:@"newPics/thumb/thumb1.png" ]];
if (tot==5) {
break;
}
if (5==nimages) {
nimages=0;
}

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

CGRect rect = imageView.frame;
rect.size.height = 150;
rect.size.width = 150;
rect.origin.x = cx;
rect.origin.y = 0;

imageView.frame = rect;


[_thumbnailScroll addSubview:imageView];
_thumbnailScroll.userInteractionEnabled = YES;
// [imageView release];

cx += imageView.frame.size.width+100;
tot++;
}

//self.pageControl.numberOfPages = nimages;
[_thumbnailScroll setContentSize:CGSizeMake(cx, [_thumbnailScroll bounds].size.height)];

有任何想法吗 ?

最佳答案

将此用于循环内的点击监听器。

 UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self    action:@selector(onSingleTapGestureRecognized:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
singleTap.delegate = self;
[imageview1 addGestureRecogniser:singleTap];
[singleTap1 release];

imageview1.userInteractionEnabled = YES;



由 MANIAK_dobrii 给出的 Action 方法。

关于ios - 检测在 uiscrollView 中点击了哪个 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26360677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com