UIScrollView中的UIButton不会点亮 [英] UIButton inside UIScrollView doesn't fire on tap

查看:115
本文介绍了UIScrollView中的UIButton不会点亮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIScrollView中的UIButton无法点击。请帮忙解决它。

UIButton inside UIScrollView doesn't fire on tap. Please help resolve it.

 // Add a button
 UIButton *btn1 = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
 btn1.frame = CGRectMake(0, 0, 26, 18); 
 btn1.bounds = CGRectMake(0, 0, 30.0, 30.0); 
 [btn1 addTarget:self action:@selector(buttonClick1:) 
                      forControlEvents:UIControlEventTouchUpInside];
 [scrollView addSubview:btn1];


- (void)buttonClick1:(id)sender {
     int dd = 4; 
 }


推荐答案

我找到了这个东西:


但是除非你设置
userInteractionEnabled和
exclusiveTouch属性,否则scrollview将阻止按钮的
触摸在
滚动视图中为NO。但是这会打败我认为在
a按钮内设置滚动视图的
目的。

But the scrollview will block the touches from the button unless you set userInteractionEnabled and exclusiveTouch properties to NO on the scrollview. But that would defeat the purpose of having a scrollview inside a button I think.

(参见我们可以在UIScrollView中放置一个UIButton反之亦然iPhone

但该怎么办?

假设你有一个UIScrollView * sv ... then

Say you have a UIScrollView *sv ... then

sv.userInteractionEnabled = YES;
sv.exclusiveTouch = YES;

我还要添加

sv.canCancelContentTouches = YES;
sv.delaysContentTouches = YES;

这篇关于UIScrollView中的UIButton不会点亮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆