【发布时间】:2013-10-02 14:54:18
【问题描述】:
我有一个包含许多图像的滚动视图。我选择使用点击手势。
选择图像是这样设置的。这部分已成功完成!
但我的问题是当我点击另一个时它给了我多个选择。我想删除以前的选择。
我想要这样的东西,当我选择下一张图片时,前一张被取消选择。
抱歉,解释不好。
提前致谢。
创建滚动视图的代码
//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;
}
}
【问题讨论】:
-
确定这不是一个集合视图,您能否提供一些代码如何将状态设置为选中?
-
是的,它是滚动视图而不是集合视图。
标签: iphone ios objective-c uitapgesturerecognizer