ios – UIScrollView中的UIControll未接收到触摸事件

ios – UIScrollView中的UIControll未接收到触摸事件,第1张

概述我在我的项目中使用 SevenSwitch.我需要将它添加到UIScrollView中,但是当我将它添加到滚动视图中时,控件似乎无法接收触摸事件. 我尝试了子类滚动视图并覆盖下面的代码: - (BOOL)touchesShouldCancelInContentView:(UIView *)view { return NO;} 还补充说: self.scrollView.delaysConte 我在我的项目中使用 SevenSwitch.我需要将它添加到UIScrollVIEw中,但是当我将它添加到滚动视图中时,控件似乎无法接收触摸事件.

我尝试了子类滚动视图并覆盖下面的代码:

- (BOol)touchesShouldCancelinContentVIEw:(UIVIEw *)vIEw {  return NO;}

还补充说:

self.scrollVIEw.delaysContenttouches = NO;

但仍然无法接收触摸事件.如何阻止scrollvIEw阻止UIControl接收触摸?

更新

我在滚动视图上有一个轻击手势,因为我想在用户点击滚动视图时调用[self.scrollVIEw endEditing:YES]来关闭键盘.当我将其拆下时,七个开关正在使用水龙头.

我将下面的代码添加到我的点按手势中:

tap.cancelstouchesInVIEw = NO;

现在sevenswitch正在使用水龙头,但是通过触摸跟踪打开或关闭开关时会出现问题.

解决方法 我已经制作了样本,其中我在scrollvIEw中有sevenswitch并且它正常工作
- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];    SevenSwitch *mySwitch = [[SevenSwitch alloc] initWithFrame:CGRectZero];    mySwitch.center = CGPointMake(self.vIEw.bounds.size.wIDth * 0.5,self.vIEw.bounds.size.height * 0.5);    [mySwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];    //[self.vIEw addSubvIEw:mySwitch];    mySwitch.on = true;    [_cntVIEw addSubvIEw:mySwitch];    SevenSwitch *mySwitch3 = [[SevenSwitch alloc] initWithFrame:CGRectZero];    mySwitch3.center = CGPointMake(self.vIEw.bounds.size.wIDth * 0.5,self.vIEw.bounds.size.height * 0.5 + 70);    [mySwitch3 addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];    [self.vIEw addSubvIEw:mySwitch3];    //self.vIEw.backgroundcolor = [UIcolor colorWithRed:0.19f green:0.23f blue:0.33f Alpha:1.00f];    mySwitch3.thumbTintcolor = [UIcolor colorWithRed:0.19f green:0.23f blue:0.33f Alpha:1.00f];    mySwitch3.activecolor = [UIcolor colorWithRed:0.07f green:0.09f blue:0.11f Alpha:1.00f];    mySwitch3.inactivecolor = [UIcolor colorWithRed:0.07f green:0.09f blue:0.11f Alpha:1.00f];    mySwitch3.onTintcolor = [UIcolor colorWithRed:0.45f green:0.58f blue:0.67f Alpha:1.00f];    mySwitch3.bordercolor = [UIcolor clearcolor];    mySwitch3.shadowcolor = [UIcolor blackcolor];    [_cntVIEw addSubvIEw:mySwitch3];}- (voID)switchChanged:(SevenSwitch *)sender {    NSLog(@"Changed value to: %@",sender.on ? @"ON" : @"OFF");}

其中_cntVIEw是我放置在scrollvIEw中的主容器视图,请检查这是否适合您

更新

正如我在评论中提到的,我没有得到你想用触摸跟踪说的但我已经在滚动视图中使用点击手势制作样本可能有所帮助

UIScrollVIEw *scrollvIEw = [[UIScrollVIEw alloc] initWithFrame:CGRectMake(0,self.vIEw.frame.size.wIDth,self.vIEw.frame.size.height)];    [scrollvIEw setContentSize:CGSizeMake(self.vIEw.frame.size.wIDth,700)];    [self.vIEw addSubvIEw:scrollvIEw];    SevenSwitch *mySwitch = [[SevenSwitch alloc] initWithFrame:CGRectZero];    mySwitch.center = CGPointMake(self.vIEw.bounds.size.wIDth * 0.5,self.vIEw.bounds.size.height * 0.5);    [mySwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];    //[self.vIEw addSubvIEw:mySwitch];    mySwitch.on = true;    [scrollvIEw addSubvIEw:mySwitch];    SevenSwitch *mySwitch3 = [[SevenSwitch alloc] initWithFrame:CGRectZero];    mySwitch3.center = CGPointMake(self.vIEw.bounds.size.wIDth * 0.5,self.vIEw.bounds.size.height * 0.5 + 70);    [mySwitch3 addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];    mySwitch3.thumbTintcolor = [UIcolor colorWithRed:0.19f green:0.23f blue:0.33f Alpha:1.00f];    mySwitch3.activecolor = [UIcolor colorWithRed:0.07f green:0.09f blue:0.11f Alpha:1.00f];    mySwitch3.inactivecolor = [UIcolor colorWithRed:0.07f green:0.09f blue:0.11f Alpha:1.00f];    mySwitch3.onTintcolor = [UIcolor colorWithRed:0.45f green:0.58f blue:0.67f Alpha:1.00f];    mySwitch3.bordercolor = [UIcolor clearcolor];    mySwitch3.shadowcolor = [UIcolor blackcolor];    [scrollvIEw addSubvIEw:mySwitch3];    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionSingleTap:)];    singleTap.numberOfTapsrequired = 1;    singleTap.cancelstouchesInVIEw = NO;    [scrollvIEw addGestureRecognizer:singleTap];}- (voID)actionSingleTap:(UITapGestureRecognizer *)sender {    NSLog(@"Tap");}- (voID)switchChanged:(SevenSwitch *)sender {    NSLog(@"Changed value to: %@",sender.on ? @"ON" : @"OFF");}

我已经以编程方式创建了所有新代码,它还检测到sevenSwitch外部的触摸事件,并且还检测到七个开关上的触摸/点击.如果您想在Storyboard中进行滚动视图并使用故事板插座更改编程滚动视图

总结

以上是内存溢出为你收集整理的ios – UIScrollView中的UIControll未接收到触摸事件全部内容,希望文章能够帮你解决ios – UIScrollView中的UIControll未接收到触摸事件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1100758.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存