gpt4 book ai didi

iphone - UIScrollView 内 View 中的 UIgestureRecognizer

转载 作者:行者123 更新时间:2023-12-03 18:37:40 26 4
gpt4 key购买 nike

有没有人设法让 UIGestureRecognizer 在作为 UIScrollView subview 的 UIView 上工作?我的回调似乎从未被调用。

作为一个简单的示例,我想要一个分页 ScrollView ,并在第三页上使用 UITapGestureRecognizer 监听点击。但是我无法让它工作。

我会这样做:

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 addGestureRecognizer:p2TapRegocnizer];

最佳答案

UIImageView 默认 userInteractionEnabled 设置为 NO。我会尝试将其更改为"is"。

关于iphone - UIScrollView 内 View 中的 UIgestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3005903/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com