Iphone 带UICapgestureRecognitor和UIPageControl的UIScrollView
我正在创建一个包含图像的水平滚动表视图。我的刷卡功能运行良好,并且能够将图像添加到Iphone 带UICapgestureRecognitor和UIPageControl的UIScrollView,iphone,scrollview,uigesturerecognizer,uipagecontrol,Iphone,Scrollview,Uigesturerecognizer,Uipagecontrol,我正在创建一个包含图像的水平滚动表视图。我的刷卡功能运行良好,并且能够将图像添加到滚动视图,就像在cellforrowatinexpath中一样: scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, tv.frame.size.width, 78)]; [scrollView setContentSize:CGSizeMake(700, 78)]; UIImage *footImage = [UIIm
滚动视图
,就像在cellforrowatinexpath
中一样:
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, tv.frame.size.width, 78)];
[scrollView setContentSize:CGSizeMake(700, 78)];
UIImage *footImage = [UIImage imageNamed:@"Foot.png"];
UIImageView *footImageView = [[UIImageView alloc] initWithImage:footImage];
footImageView.frame = CGRectMake(0, 0, 80, 78);
footImageView.userInteractionEnabled = YES;
[scrollView addSubview: footImageView];
UIImage *handImage = [UIImage imageNamed:@"Hand.png"];
UIImageView *handImageView = [[UIImageView alloc] initWithImage:handImage];
handImageView.frame = CGRectMake(90, 0, 80, 78);
handImageView.userInteractionEnabled = YES;
[scrollView addSubview: handImageView];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(highlightImage)];
[scrollView addGestureRecognizer:tapGesture];
NSLog(@"tapGesture added to scrollView");
[[cell contentView] addSubview:scrollView];
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 50, tv.frame.size.width, 50)];
[pageControl setNumberOfPages:4];
[[cell contentView] addSubview:pageControl];
我的点击手势
正在向选择器注册,hightlightImage
,并记录它是否正确调用了此方法
- (void) highlightImage
{
NSLog(@"tapping tapping");
}
我工作的真正目的是,如果点击,可以突出显示/选择这些图像,如果再次点击,可以突出显示/取消选择这些图像。我将在屏幕上有另一个按钮,将导航到下一页(这里不相关)
我走的路对吗?显然,我将以这种方式填充
UIImages
的NSArray
,并填充scrollView
,但现在只需将其加上尖峰即可。如果有人能给我一些指导或示例,说明如何使每个按钮分别可选择/取消可选择,那就太好了:)使用UIButton而不是UIImageView
它有内置的选择功能
摆脱手势,在每个按钮上添加highlightImage作为动作
将您的highlightImage
转换为highlightImage:(id)发送者
发送者应该是一个按钮,这样你就可以
[发件人:是] 轰!我已经迁移到使用UIButtons,但甚至没有想到将每个按钮的操作用于UIControlEventTouchUpInside
。我的新highlightImage
方法正在拾取它所发送的不同发送者(每个ui按钮
实例)。现在,我使用一种方法createScrollButtons
在scrollview中的所需位置创建每个按钮。我必须为要创建的每个按钮调用addTarget:action:forControlEvents:
。Id真正喜欢的是某种类型的循环,因此请检查每个ui按钮
,以创建它们,并将它们放置在滚动视图的正确位置。