开发者

UIgestureRecognizer in a view inside a UIScrollView

Has anyone managed to get a UIGestureRecognizer to work on a UIView that is a subview of a UIScrollView? My callbacks never seems to get called.

As a simple example, I want to have a paging scrollview and on the third page listen for a tap with a UITapGestureRecognizer. However I can not get it to work.

Here's how I would do it:

self.scrollView = [[[UIScrollView alloc] initWithFrame:self.view.frame] autorelease];
self.scrollView.pagingEnabled = YES;
self.scrollView.contentSize = CGSizeMake(self.section1ScrollView.frame.size.width * 3, self.scrollView.frame.size.height); //3 pages

UIImageView *p0 = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"page0.png"]] autorelease];
[self.scrollView insertSubview:p0 atIndex:self.scrollView.subviews.count];

UIImageView *p1 = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"page1.png"]] autorelease];
//code to move it to the next page
[self.scrollView insertSubview:p1 atIndex:self.scrollView.subviews.count];

UIImageView *p2 = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"page2.png"]] autorelease];
//code to move it to the next page
[self.scrollView insertSubview:p2 atIndex:self.scrollView.subviews.count];

UITapGestureRecognizer *p2TapRegocnizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(p2Tapped:)] autorelease];
//p2TapRegocnizer.delegate = self;
[p2 addGestureRe开发者_如何学Pythoncognizer:p2TapRegocnizer];


UIImageView has in default userInteractionEnabled set to NO. I would try to change it to YES.


[webView setUserInteractionEnabled:YES]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜