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三个属性是相互关联、相互影响的,其中一个属性发生变化,其他属性也会跟着变化。
UIView详解2的更多相关文章
- UIView详解
MVC架构模式 MVC(Model-View-Controller)是实现数据和显示数据的视图分离的架构模式(有一定规模的应用都应该实现数据和显示的分离).其中,M代表模型,就是程序中使用的数据和 ...
- UI第三节——UIView详解
- (void)viewDidLoad { [super viewDidLoad]; UIView *redView = [[UIView alloc] initWithFrame:CGRectMak ...
- UIView详解1
一个UIView的实例就是一个视图,表示的是屏幕上的一块矩形区域,负责这块矩形区域的描绘以及和用户的交互. 第一.UIView的可视化属性 1. backgroundColor 背景属性 2. hi ...
- 《iOS 7 应用开发实战详解》
<iOS 7 应用开发实战详解> 基本信息 作者: 朱元波 管蕾 出版社:人民邮电出版社 ISBN:9787115343697 上架时间:2014-4-25 出版日期:2014 年5 ...
- 详解CALayer 和 UIView的区别和联系
详解CALayer 和 UIView的区别和联系 前言 前面发了一篇iOS 面试的文章,在说到 UIView 和 CALayer 的区别和联系的时候,被喵神指出没有切中要点,所以这里就 CALay ...
- 【好程序员笔记分享】——UIView与CALayer详解
-iOS培训,iOS学习-------型技术博客.期待与您交流!------------ UIView与CALayer详解 研究Core Animation已经有段时间了,关于Core Animati ...
- 【iOS自定义键盘及键盘切换】详解
[iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...
- iOS开发——加载、滑动翻阅大量图片解决方案详解
加载.滑动翻阅大量图片解决方案详解 今天分享一下私人相册中,读取加载.滑动翻阅大量图片解决方案,我想强调的是,编程思想无关乎平台限制. 我要详细说一下,在缩略图界面点击任意小缩略图后,进入高清 ...
- UI第六节——UINavigationController 详解
1. UINavigationController 是一个容器类.里面盛放的是UIViewController. 容器的意思是,如果你不放入UIViewController,里面就是空的,什么也没有. ...
随机推荐
- rsync Backups for Windows
Transfer your Windows Backups to an rsync server over SSH rsync.net provides cloud storage for offsi ...
- SetFocus、SetCapture和SetActiveView的区别
1. SetActiveView是MFC框架内的一个函数, 而不是SDK中的函数, 也就是说SDK中没有ActiveView这个概念, 只有在MFC中才有2. SetFocus是SDK中的函数(当然M ...
- c#2解决c#1中的问题之用泛型实现参数化类型
为什么需要泛型 你手中还有c#1的代码吗?数一数其中的强制转换有多少,特别是那些大量使用集合的代码.几乎每次使用foreach都需要隐式的强制转换.使用那些为不同数据类型而设计的类型,就意味着强制转换 ...
- FindWindowEx使用方法
函数功能:该函数获得一个窗体的句柄,该窗体的类名和窗体名与给定的字符串相匹配.这个函数查找子窗体,从排在给定的子窗体后面的下一个子窗体開始.在查找时不区分大写和小写. 函数原型:HWND FindWi ...
- wake_lock_timeout的用法
今天实用到用ec43_GPIO的中断来唤醒系统,将系统从深度休眠中唤醒并保证系统wakup 一段时间用过了.方法例如以下.有相同使用的童鞋能够參考一下. 1. 定义一人局部静态变量ec43_wlo ...
- Android资源管理框架(Asset Manager)简介和学习计划
Android该应用程序包括两个部分组成的:代码和资源. 资源主要是与UI相关的东西,例如UI布局.和其他字符串和照片.代码和资源可以使独立的应用程序来组织的实际需求的基础上,在执行的时候UI.,就能 ...
- What is the difference between JRE,JVM and JDK?
If you are a Java developer, it is very often that you think about understanding the JRE,JVM and JDK ...
- 分布式发布订阅消息系统Kafka
高吞吐量的分布式发布订阅消息系统Kafka--安装及测试 一.Kafka概述 Kafka是一种高吞吐量的分布式发布订阅消息系统,它可以处理消费者规模的网站中的所有动作流数据. 这种动作(网页浏览, ...
- RIA Test:try catch 对 Error #1009 (无法访问空对象引用的属性或方法)的处理
功能: 实现登录账户的强制登录, 用If 判断当前账户是否可用.若可用,则跳出if体直接登录,若不可用,则进入If体点击 “强制登录” 按钮. 问题:如果不可用,则if 条件中的对象不可见,这样程序会 ...
- 1.SQL统计某张表的列数。
select count(syscolumns.name) from syscolumns , sysobjects where syscolumns.id ...