首页 > 代码库 > 点击textField没有响应与在屏幕上未看到创建的视图问题(UI)
点击textField没有响应与在屏幕上未看到创建的视图问题(UI)
一.点击textField没有响应
(1)textField上面还有视图(如下)
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, 220, 40)];
tf.backgroundColor = [UIColor yellowColor];
tf.borderStyle = UITextBorderStyleRoundedRect;
[self.window addSubview:tf];
[tf release];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
view.backgroundColor = [UIColor redColor];
[self.window addSubview:view];
[view release];
(2)textField 超出父视图的管理范围
视图能够管理它范围内所有的子视图,如果子视图超出了父视图的范围,就无法响应交互.(如下)
UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
bgView.backgroundColor = [UIColor redColor];
//将自己视图内超出自身管理范围的子视图裁减掉.
bgView.clipsToBounds = YES;
[self.window addSubview:bgView];
[bgView release];
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(0, 20, 320, 40)];
tf.backgroundColor = [UIColor greenColor];
tf.borderStyle = UITextBorderStyleRoundedRect;
[bgView addSubview:tf];
[tf release];
(3)自身问题引起的点击不响应(如下)
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(50, 200, 220, 40)];
tf.backgroundColor = [UIColor greenColor];
//设置能否编辑
// tf.enabled = NO;
//设置是否响应用户交互
tf.userInteractionEnabled = NO;
tf.borderStyle = UITextBorderStyleRoundedRect;
[self.window addSubview:tf];
[tf release];
(4)textField父视图不可交互(如下)
//UILabel默认的用户交互是关闭的.
UILabel *view = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
view.backgroundColor = [UIColor redColor];
view.userInteractionEnabled = YES;
[self.window addSubview:view];
[view release];
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(0, 40, 320, 40)];
tf.backgroundColor = [UIColor greenColor];
tf.borderStyle = UITextBorderStyleRoundedRect;
[view addSubview:tf];
[tf release];
二.在屏幕上未看到创建的视图
(1)未添加到父视图(如下)
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
view.backgroundColor = [UIColor redColor];
[self.window addSubview:view];
[view release];
(2)视图没有设置颜色,颜色依然为clearColor.
(3)未设置frame
(4)创建视图方法未调用
(5)添加的父视图为nil
UIView *view = nil;
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
view1.backgroundColor = [UIColor redColor];
[view addSubview:view1];
[view1 release];
(1)textField上面还有视图(如下)
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, 220, 40)];
tf.backgroundColor = [UIColor yellowColor];
tf.borderStyle = UITextBorderStyleRoundedRect;
[self.window addSubview:tf];
[tf release];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
view.backgroundColor = [UIColor redColor];
[self.window addSubview:view];
[view release];
(2)textField 超出父视图的管理范围
视图能够管理它范围内所有的子视图,如果子视图超出了父视图的范围,就无法响应交互.(如下)
UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
bgView.backgroundColor = [UIColor redColor];
//将自己视图内超出自身管理范围的子视图裁减掉.
bgView.clipsToBounds = YES;
[self.window addSubview:bgView];
[bgView release];
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(0, 20, 320, 40)];
tf.backgroundColor = [UIColor greenColor];
tf.borderStyle = UITextBorderStyleRoundedRect;
[bgView addSubview:tf];
[tf release];
(3)自身问题引起的点击不响应(如下)
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(50, 200, 220, 40)];
tf.backgroundColor = [UIColor greenColor];
//设置能否编辑
// tf.enabled = NO;
//设置是否响应用户交互
tf.userInteractionEnabled = NO;
tf.borderStyle = UITextBorderStyleRoundedRect;
[self.window addSubview:tf];
[tf release];
(4)textField父视图不可交互(如下)
//UILabel默认的用户交互是关闭的.
UILabel *view = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
view.backgroundColor = [UIColor redColor];
view.userInteractionEnabled = YES;
[self.window addSubview:view];
[view release];
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(0, 40, 320, 40)];
tf.backgroundColor = [UIColor greenColor];
tf.borderStyle = UITextBorderStyleRoundedRect;
[view addSubview:tf];
[tf release];
二.在屏幕上未看到创建的视图
(1)未添加到父视图(如下)
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
view.backgroundColor = [UIColor redColor];
[self.window addSubview:view];
[view release];
(2)视图没有设置颜色,颜色依然为clearColor.
(3)未设置frame
(4)创建视图方法未调用
(5)添加的父视图为nil
UIView *view = nil;
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
view1.backgroundColor = [UIColor redColor];
[view addSubview:view1];
[view1 release];
点击textField没有响应与在屏幕上未看到创建的视图问题(UI)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。