zoukankan      html  css  js  c++  java
  • UIView详解2

    第三、Configuring the Event-Related Behavior

    1.  userInteractionEnabled  property

     

    A Boolean value that determines whether user events are ignored and removed from the event queue.

    @property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled

    最简单的比如说让给一个button在点击时,没有响应,可以设置这个值为no

    2.  multipleTouchEnabled  property

     

    A Boolean value that indicates whether the receiver handles multi-touch events.

    @property(nonatomic, getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled

    Discussion

    When set to YES, the receiver receives all touches associated with a multi-touch sequence. When set toNO, the receiver receives only the first touch event in a multi-touch sequence. The default value of this property isNO.

    Other views in the same window can still receive touch events when this property isNO. If you want this view to handle multi-touch events exclusively, set the values of both this property and theexclusiveTouch property to YES.

    3.   exclusiveTouch  property

     

    A Boolean value that indicates whether the receiver handles touch events exclusively.

    第四

    1.frame:

    描述当前视图在其父视图中的位置和大小,用位置坐标和长度来表示:

    sample:

     

    UIButton *button3=[[[UIButtonalloc] initWithFrame:CGRectMake(120,120, 100,100)] autorelease];

        button3.backgroundColor=[UIColorgreenColor];

        [self.view addSubview:button3];

        NSLog(@"the result is %f,%f,%f,%f",button3.frame.size.height,button3.frame.size.width,button3.frame.origin.x,button3.frame.origin.y);

    结果:

     

    the result is 100.000000,100.000000,120.000000,120.000000

    2. bounds  property

    描述当前视图在其自身坐标系统中的位置和大小。

    iphone中坐标系统的建立,最左上角是原点(0,0),向右为x轴递增,想下为y轴递减。

     

    ios采用CGPoint来表示点在坐标系上X、Y位置。我们可以通过CGPointMake(x,y)来创建一个坐标点:CGPoint point = CGPointMake(80,40)

    同时,ios采用CGSize来表示视图的宽度和高度,即视图的大小。我们可以通过CGSizeMake(width,height)来创建一个矩形的大小,如CGSize size = CGSizeMake(144,72)将创建一个宽度为144,高度为72的矩形大小。

    而CGRect则是结合了CGPoint和CGSize,用来表示矩形的位置和大小。它的origin表示矩形右上角所在位置(CGPoint),size表示矩形的大小(CGSize)。

    sample:

     

     

      UIButton *button3=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 100, 100)] autorelease];
        button3.backgroundColor=[UIColor greenColor];
        [self.view addSubview:button3];
        NSLog(@"the result is %f,%f,%f,%f",button3.frame.size.height,button3.frame.size.width,button3.frame.origin.x,button3.frame.origin.y);
        
        NSLog(@"the result is %f,%f,%f,%f",button3.bounds.origin.x,button3.bounds.origin.y,button3.bounds.size.height,button3.bounds.size.width);
    }

     

    3.center  property

    描述当前视图的中心点在其父视图中的位置。

    sample如下所示:

        UIButton *button3=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 100, 100)] autorelease];
        button3.backgroundColor=[UIColor greenColor];
        [self.view addSubview:button3];
        NSLog(@"the result is %f,%f",button3.center.x,button3.center.y);
    

    result is:

     

    the result is 170.000000,170.000000

    4.frame.bounds 和center的区别和联系

    这两个属性都是用来描述视图的大小(CGSize)和位置(CGPoint)的,两者都用CGRect表示。不同的是,frame描述的是在其父视图中的CGRect,而bounds描述的是在其自身视图中的CGRect,

    center属性则用CGPoint表示矩形中心点在其父视图中的位置,如图3中View B的center属性为(300,200)。

    frame、bounds和center三个属性是相互关联、相互影响的,其中一个属性发生变化,其他属性也会跟着变化。


  • 相关阅读:
    函数指针和指针函数和回调函数以及函数指针数组
    C语言中的结构体,结构体数组
    linux中的shell脚本编程
    回车和换行在linux下和windows下
    内存的段式管理和页式管理,逻辑地址-虚拟地址-物理地址
    [CSAPP-II] 链接[符号解析和重定位] 静态链接 动态链接 动态链接接口
    c语言中函数调用的本质从汇编角度分析
    运算符优先级
    Redis实战经验及使用场景
    RESTful API 设计最佳实践【转】
  • 原文地址:https://www.cnblogs.com/riskyer/p/3297100.html
Copyright © 2011-2022 走看看