现在的位置: 首页 > 综合 > 正文

UIView的事件相关属性和tag属性

2013年12月08日 ⁄ 综合 ⁄ 共 2412字 ⁄ 字号 评论关闭

第三、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.

第四. 利用tag来查找UIView

    [superviewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    UIView *view1=[[[UIViewalloc]
initWithFrame:CGRectMake(50,50,
100,100)]
autorelease];

    view1.backgroundColor=[UIColorredColor];

    view1.tag=101;

    [self.view
addSubview
:view1];

    

    UIView *view2=[[[UIViewalloc]
initWithFrame:CGRectMake(150,150,
200,200)]
autorelease];

    view2.backgroundColor=[UIColorblueColor];

    view2.tag=102;

    [self.view
addSubview
:view2];

    

    

    UIView *view3=[[[UIViewalloc]
initWithFrame:CGRectMake(150,150,
200,200)]
autorelease];

    view3.backgroundColor=[UIColorblueColor];

    view3.tag=103;

    [view2 addSubview:view3];

    

    NSLog(@"the view1 is %@",[self.viewviewWithTag:102]);

    NSLog(@"the subviews are %@",[self.viewsubviews]);

    NSLog(@"the superview is %@",[view3superview]);

输出结果为:

2013-09-06 19:48:27.550 test[1501:c07] the bound is {{0, 0}, {320, 480}}
2013-09-06 19:48:27.553 test[1501:c07] the view1 is <UIView: 0x761e350; frame = (150 150; 200 200); tag = 102; layer = <CALayer: 0x761e3b0>>
2013-09-06 19:48:27.553 test[1501:c07] the subviews are (
    "<UIView: 0x761e170; frame = (50 50; 100 100); tag = 101; layer = <CALayer: 0x761ddb0>>",
    "<UIView: 0x761e350; frame = (150 150; 200 200); tag = 102; layer = <CALayer: 0x761e3b0>>"
)
2013-09-06 19:48:27.554 test[1501:c07] the superview is <UIView: 0x761e350; frame = (150 150; 200 200); tag = 102; layer = <CALayer: 0x761e3b0>>

第五、当调用addsubView的时候,会对其进行保留,理解为retain一个对象就可以,当调用removeFromSuperView,会对释放,也就是release

如果手动创建了视图,分配了任何内存、存储了任何对象的引用,都需要释放资源,必须实现dealloc方法,当某个对象的引用计数为0时,系统会调用dealloc方法,去释放对象的资源,切记不要手动调用dealloc方法

抱歉!评论已关闭.