我需要从滚动视图中选择多个图像。
如果我触摸该图像,则会显示选择标记(勾号)标记;如果我再次触摸它,那么它将被取消选择。
现在我这样做:
我希望这样当我点击该特定图像时,它会显示一个勾号(勾号)标记;如果我触摸第二个,那么它将显示该图像的一个刻度(检查),就像我们从相机胶卷中选择图像一样。
所以,请尽快帮助我。
以下是我的代码:
-(void)listimagesandanmae
{
int myFavV = [favCompcamelIDArr count];
for (int i = 0; i < myFavV; i++)
{
CGFloat xOrigin = i * 100;
favimageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin+20,10,70,70)];
favimageView.layer.cornerRadius = favimageView.frame.size.width / 2;
favimageView.clipsToBounds = YES;
// imageView.layer.cornerRadius = 60;
// imageView.clipsToBounds = YES;
favimageView.tag=i;
NSInteger tag = favimageView.tag;
// then do what you want with this
if (([favCompcamelIDArr count] >0) ) {
}
favnamelistingLbl=[[UILabel alloc]initWithFrame:CGRectMake(xOrigin+23,90,90,27)];
favnamelistingLbl.textAlignment = NSTextAlignmentCenter;
favnamelistingLbl.tag=i;
NSLog(@"%lu",(unsigned long)[favcompnsmeArr count]);
if (([favCompcamelIDArr count] > 0) ) {
favnamelistingLbl.text=[favcompnsmeArr objectAtIndex:i];
}
[_selectCamelFav addSubview:favnamelistingLbl];
UITapGestureRecognizer *tappedmyFav = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedmyFav:)];
tappedmyFav.numberOfTapsRequired = 1;
[favimageView addGestureRecognizer:tappedmyFav];
NSLog(@"%ld",(long)tag);
NSString *urStCam=@"http://192.8.1.42:/da/";
NSString *urStCam1=[urStCam stringByAppendingString:[favcompictureArr objectAtIndex:i]];
NSString *urStCam2= [urStCam1 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
[caArray addObject:urStCam2];
NSLog(@"%@",caArray);
NSURL *newUrl=[NSURL URLWithString:[caArray objectAtIndex:i]];
NSData *imageDatash = [NSData dataWithContentsOfURL:newUrl];
UIImage *image123 = [UIImage imageWithData:imageDatash scale:2.0];
[favimageView setImage:image123];
[_selectCamelFav addSubview:favimageView];
favimageView.userInteractionEnabled = YES;
}
_selectCamelFav.contentSize = CGSizeMake(myFavV * 210, 171);
[_indicatorA startAnimating];
_indicatorA.hidden=YES;
}
- (void)tappedmyFav:(UITapGestureRecognizer*)tap
{
UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) tap;
}
答案 0 :(得分:0)
你应该是UIView的子类。然后添加UIImageView,UILabel(复选标记)和属性来控制是否选择了UIView。还添加Tap手势处理程序(选择=!点击时选择)
要搜索选择了哪个视图,请在滚动视图中搜索“已选择”&#39; UIView对象。或者,一旦对象被选中/未被选中,您就可以维护自己的列表。这样您就不需要搜索所有对象。