多くの画像を含むスクロールビューがあります。タップジェスチャを使用して選択しています。
選択画像はそのように設定されています。この部分は正常に完了しました。
しかし、私の問題は、別のものをタップすると複数選択できることです。以前の選択を削除したいです。
次の画像を選択すると、前の画像が選択解除されます。
すみません、説明が悪くて。
前もって感謝します。
スクロールビューを作成するコード
//below code are for create scroll view
-(void)viewDidLoad{
scrollView.delegate = self;
scrollView.scrollEnabled = YES;
int scrollWidth = 70;
scrollView.contentSize = CGSizeMake(scrollWidth,50);
int xOffset = 0;
for(int index=0; index < [imagesName count]; index++)
{
img = [[UIImageView alloc] init];
[img setUserInteractionEnabled:YES];
img.bounds = CGRectMake(0, 0, 60, 40);
img.frame = CGRectMake(5+xOffset, 5, 60, 40);
//below line add here
img.image = [UIImage imageNamed:[imagesName objectAtIndex:index]];
img.tag = 303 + index;
// [img.layer setBorderColor:[UIColor whiteColor].CGColor];
// [img.layer setBorderWidth:2.0f];
[Scrollimages insertObject:img atIndex:index];
scrollView.contentSize = CGSizeMake(scrollWidth+xOffset,50);
[scrollView addSubview:[Scrollimages objectAtIndex:index]];
//xOffset += 170;
xOffset += 70;
}
for (UIImageView *scrollimage in Scrollimages) {
UITapGestureRecognizer *singleTapRecognizerInScroll = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewsingleTappedInScrollMethod:)];
singleTapRecognizerInScroll.delegate = self;
singleTapRecognizerInScroll.numberOfTapsRequired = 1;
singleTapRecognizerInScroll.numberOfTouchesRequired = 1;
[scrollimage addGestureRecognizer:singleTapRecognizerInScroll];
}
}
-(void)scrollViewsingleTappedInScrollMethod:(UITapGestureRecognizer *)recognizer{
scrollimageview = (UIImageView *)recognizer.view;
//we select the image using tag.(contain many images)
if ([scrollimageview tag] == 303) {
selectLimitSet = 3;
}
}