美文网首页
3.7 IOS UIView视图userInteractionE

3.7 IOS UIView视图userInteractionE

作者: 草根小强 | 来源:发表于2019-04-10 16:21 被阅读0次

userInteractionEnabled中的User是指的用户者当前视图设为view.userInteractionEnabled=NO 时,当前视图不可交互,该视图上面的子视图也不可与用户交互(不可响应即被该视图忽视),响应事件传递到下面的父视图。
当前视图设为view.userInteractionEnabled=YES 时,当前视图可交互,该视图上面的子视图可以用户交互(可以响应即被视图接受),下面的父视图不会接收到响应。

UIImageView 默认的userInteractionEnabled是NO;
UILabel默认 userInteractionEnabled是NO;
UIView的userInteractionEnabled默认是YES。
当视图对象的userInteractionEnabled设置为NO的时候,用户触发的事件,如触摸事件,键盘弹出事件。。等,将会被该视图忽略(其他视图照常响应),并且该视图对象也会从事件响应队列中被移除。当userInteractionEnabled设为YES时,则事件可以正常的传递给该视图对象。
注意::响应者链是能够响应事件的对象组成的链,事件在该链上传递,最终结果事件或被处理或被抛弃。所以一个对象在不在响应者链里是其能否响应事件的首要前提条件!

image.png
//
//alpha//alpha  = 0  与 hidden 一样的
//hidden//是否隐藏视图    //不能有任何事件交互

//clipsToBounds //(超出父视图的范围进行裁剪)
//情况一:  button禁用
//情况二: 如下:超出父视图的部分不能够响应任何的事件的
#warning 超出父视图的部分不能够响应任何的事件的
#warning  关于addSubView 和 removeFromsuperView的内存管理,因为 addSubView 加一  然后removeFromsuperView减一  
- (void)aboutProperty{
     //父子视图的关系
     //父视图
    UIView *superView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
    
    superView.backgroundColor = [UIColor purpleColor];
    [self.view addSubview:superView];
    NSLog(@"--%@",NSStringFromCGPoint(superView.center));
//    superView.alpha = 0;
    
    //子视图
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    //target 接收消息
    //action  发送消息
    // id 调用action 里面的方法
    
    [button addTarget:self action:@selector(showLog) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 100, 100);
    button.backgroundColor = [UIColor greenColor];
    
    [superView addSubview:button];
    
    //中心点属性
    //
    button.center = superView.center;
//  button.center = CGPointMake(200, 200);
    
//    button.alpha = 0;
    
    //YES 表示父视图  以及他的子视图 可以进行用户交互
    //NO  表示父视图  以及他的子视图 不可以进行用户交互
    superView.userInteractionEnabled = YES;
    
    
    //移除子视图
    
}
- (void)showLog{
    
    NSLog(@"click");
}

@end

相关文章

网友评论

      本文标题:3.7 IOS UIView视图userInteractionE

      本文链接:https://www.haomeiwen.com/subject/tbfoiqtx.html