UITapGestureRecognizer的使用影响视图上某些控件的action的问题
来源:互联网 发布:mac怎么使用投影仪 编辑:程序博客网 时间:2024/06/08 00:36
我的界面上的视图层次是这样的:
scrollView=[[UIScrollView alloc] initWithFrame:self.view.frame];
scrollView.backgroundColor=[UIColor clearColor];
[self.view addSubview:scrollView];
[scrollView release];
userInfoView=[[UIView alloc] initWithFrame:CGRectMake(0, 84, 320, 376)];
userInfoView.backgroundColor=[UIColor clearColor];
userInfoView.userInteractionEnabled=YES;
[scrollView addSubview:userInfoView];
[userInfoView release];
UIButton *editButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
editButton.frame=CGRectMake(93, 248, 115, 37);
editButton.userInteractionEnabled=YES;
[editButton setTitle:@"修改用户信息" forState:UIControlStateNormal];
[editButton addTarget:self action:@selector(changeUserInfo) forControlEvents:UIControlEventTouchUpInside];
[userInfoView addSubview:editButton];
UILabel *oldPassWordLabel=[[UILabel alloc] initWithFrame:CGRectMake(20, 53, 87, 20)];
oldPassWordLabel.text=@"原口令:";
oldPassWordLabel.textAlignment=UITextAlignmentLeft;
oldPassWordLabel.backgroundColor=[UIColor clearColor];
[passwordView addSubview:oldPassWordLabel];
[oldPassWordLabel release];
oldPassword=[[UITextField alloc] initWithFrame:CGRectMake(124, 48, 176,30)];
oldPassword.borderStyle=UITextBorderStyleRoundedRect;
oldPassword.clearButtonMode=UITextFieldViewModeWhileEditing;
oldPassword.text=@"";
oldPassword.delegate=self;
oldPassword.returnKeyType=UIReturnKeyNext;
//oldPassword.backgroundColor=[UIColor clearColor];
oldPassword.secureTextEntry=YES;
[passwordView addSubview:oldPassword];
[oldPassword release];
UITapGestureRecognizer* onTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
onTap.delegate = self;
[passwordView addGestureRecognizer:onTap];
[onTap release];
加上onTap之后,当我点击editButton的时候只调用handleSingleTap这个方法,不调用changeUserInfo这个方法,点击oldPassword输入内容喝点击clearButton清楚内容的时候也不好用,后来我加上这么一句话 onTap.cancelsTouchesInView=NO;然后点击按钮好用了,可是点击oldPassword还是不好用,最后发现这样可以解决这个问题:UIGestureRecognizerDelegate这个代理方法里面有这个- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if (oldPassword.superview!=nil) {
if ([touch.view isKindOfClass:[UIControl class]]) {
return NO;
}
}
return YES;
}这样就当我们点击UIControl子类的控件UIButton、UITextField、UISlider等时可以把我们触摸取消,使得控件正常使用。
- UITapGestureRecognizer的使用影响视图上某些控件的action的问题
- UITapGestureRecognizer 的使用,判断点击哪个控件
- UITapGestureRecognizer 的基本使用
- 【iOS】Button点击事件被其父视图点击手势UITapGestureRecognizer的屏蔽问题
- Asp.net下使用RequiredFieldValidator影响别的控件的问题
- 关于UITapGestureRecognizer与button的问题
- UITapGestureRecognizer 的用法
- UITapGestureRecognizer 的用法
- UITapGestureRecognizer 的用法
- UITapGestureRecognizer 的用法
- UITapGestureRecognizer 的用法
- UITapGestureRecognizer 的用法
- UITapGestureRecognizer 的用法
- UITapGestureRecognizer 的用法
- UITapGestureRecognizer的用法
- UITapGestureRecognizer 的用法
- UITapGestureRecognizer功能的实现
- UITapGestureRecognizer 的用法
- Unity3D(1)——发布设置
- 朝花夕拾-3-TLB & cache
- Intel's KVM official dev site
- win7下虚拟机VMWare装linux(ubantu)后挂载win7共享目录
- 安卓开发startservice 和bindservice详解
- UITapGestureRecognizer的使用影响视图上某些控件的action的问题
- Javascript继承机制的设计思想
- 找不到mysql.sock,mysql.sock丢失问题解决方法
- Apache+JK+Tomcat实现负载均衡
- 用unity画抛物面
- svn 服务器的android代码如何同步 git服务器上的patch
- Android中使用Animation实现控件的动画效果以及Interpolator和AnimationListener的使用
- 推荐一个新的技术网站OutOfMemory.CN
- [ubuntu12.04] u盘全自动安装 ubuntu server 12.04