UIKit 框架之UIView二
下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客
一、自定义一个View
//
// MyView.m
// UIView
//
// Created by cyw on 15-5-17.
// Copyright (c) 2015年 cyw. All rights reserved.
//
#import "MyView.h"
@implementation MyView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
//下面两个方法主要作用是事件传递、响应者链
//当在一个view上添加一个屏蔽罩,但又不影响对下面view的操作,也就是可以透过屏蔽罩对下面的view进行操作
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *hitView = [super hitTest:point withEvent:event];
if (hitView == self)
{
return nil;
}
else
{
return hitView;
}
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
return NO;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// UITouch *touch=[touches anyObject];
NSLog(@"bbbbb");
return;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
二、
//
// ViewController.m
// UIView
//
// Created by cyw on 15-5-17.
// Copyright (c) 2015年 cyw. All rights reserved.
//
#import "ViewController.h"
#import "MyView.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view1=[[UIView alloc]init];
view1.frame=CGRectMake(100, 100, 200, 200);
//允许用户交互
view1.userInteractionEnabled=YES;
//tag值
view1.tag=10001;
//layer
view1.layer.backgroundColor=[UIColor redColor].CGColor;
//UIViewGeometry
//bounds center
NSLog(@"bounds=%@\ncenter=%@",NSStringFromCGRect(view1.bounds),NSStringFromCGPoint( view1.center));
//设置view是否响应多点触摸,默认为NO
view1.multipleTouchEnabled=YES;
////设置touch是否排它,默认为NO
view1.exclusiveTouch=YES;
//是否隐藏
view1.hidden=NO;
//将像素point从view中转换到当前视图中,返回在当前视图中的像素值
CGPoint point=[view1 convertPoint:CGPointMake(200, 200) fromView:self.view];
NSLog(@"convertPoint fromView=%@",NSStringFromCGPoint(point));
// 将像素point由point所在视图转换到目标视图view中,返回在目标视图view中的像素值
CGPoint point1=[view1 convertPoint:CGPointMake(200, 200) toView:self.view];
NSLog(@"convertPoint toView=%@",NSStringFromCGPoint(point1));
// 将rect从view中转换到当前视图中,返回在当前视图中的rect
CGRect rect=CGRectMake(50, 50, 200, 200);
CGRect rect1= [view1 convertRect:rect fromView:self.view];
//将rect由rect所在视图转换到目标视图view中,返回在目标视图view中的rect
CGRect rect2=[view1 convertRect:rect toView:self.view];
NSLog(@"convertRect fromView=%@",NSStringFromCGRect(rect1));
NSLog(@"convertRect toView=%@",NSStringFromCGRect(rect2));
//子视图自适应 如果设置成NO,那么subView的autoresizingMask属性失效。
view1.autoresizesSubviews=YES;
// typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
// UIViewAutoresizingNone = 0, 不调整
// UIViewAutoresizingFlexibleLeftMargin = 1 << 0,自动调整与superView左边的距离,也就是说,与superView右边的距离不变。
// UIViewAutoresizingFlexibleWidth = 1 << 1,自动调整与superView的右边距离,也就是说,与superView左边的距离不变。
// UIViewAutoresizingFlexibleRightMargin = 1 << 2,
// UIViewAutoresizingFlexibleTopMargin = 1 << 3,
// UIViewAutoresizingFlexibleHeight = 1 << 4,
// UIViewAutoresizingFlexibleBottomMargin = 1 << 5
// };
//多个用|
view1.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
//调整view的尺寸去适应其内容
[view1 sizeToFit];
//传递view的尺寸,返回建议的子view尺寸
CGSize size=[view1 sizeThatFits:CGSizeMake(100, 150)];
NSLog(@"sizeThatFits=%@",NSStringFromCGSize(size));
//UIViewHierarchy
//UIViewRendering
//子视图超出边境裁剪
view1.clipsToBounds=YES;
//透明度
view1.alpha=0.5;
// opaque属性提示绘制系统如何处理view。如果opaque设置为YES,绘图系统会将
// view看为完全不透明,这样绘图系统就可以优化一些绘制操作以提升性能。如果设置
// 为NO,那么绘图系统结合其它内容来处理view。默认情况下,这个属性是YES。)
// 如果屏幕是静止的,那么这个opaque属性的设置与否不是一个大问题。但是,如果
// view是嵌入到scroll view中的,或者是复杂动画的一部分,不将设置这个属性的话
// 肯定会影响程序的性能!
// alpha支持animation, hidden和opaque不支持
// hidden开销小,alpha=0透明开销大,如果效果一样,用hidden好一点.
// hideen的时候view是不接收事件的,但alpha为0接收
// 当把View设置为透明的背景时,一般把opaque设置为NO,可以减少开销,对内存也好.
// 告诉系统渲染器view是否不透明,设置YES可以加快渲染,默认为YES,如果设置了alpha值,应该设置为NO
view1.opaque=YES;
// 是否清除缓冲区中不可见内容,默认为YES,如果在一个滚动操作频繁的视图中,应该设为NO,以避免重新渲染,提升性能
view1.clearsContextBeforeDrawing=YES;
//view自适应变化的方式 填充方式 左对齐、右对齐、拉伸填充等
view1.contentMode=UIViewContentModeScaleToFill;
MyView *myView=[[MyView alloc]initWithFrame:view1.frame];
myView.backgroundColor=[UIColor blackColor];
[self.view addSubview:view1];
//将自定义的MyView 放在View上面时,点击触发响应者链
[self.view addSubview:myView];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// UITouch *touch=[touches anyObject];
NSLog(@"aaaaa");
return;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
三、点击视图
2015-05-17 18:20:17.356 UIView[676:60b] bounds={{0, 0}, {200, 200}}
center={200, 200}
2015-05-17 18:20:17.358 UIView[676:60b] convertPoint fromView={100, 100}
2015-05-17 18:20:17.358 UIView[676:60b] convertPoint toView={300, 300}
2015-05-17 18:20:17.359 UIView[676:60b] convertRect fromView={{-50, -50}, {200, 200}}
2015-05-17 18:20:17.360 UIView[676:60b] convertRect toView={{150, 150}, {200, 200}}
2015-05-17 18:20:17.360 UIView[676:60b] sizeThatFits={200, 200}
2015-05-17 18:20:20.049 UIView[676:60b] aaaaa
四、上面输出可以看到输出"aaaaa"而不是"bbbb", 因为在MyView中重写了-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event屏蔽了最上面按钮的响应,而它下面的可以响应
UIKit 框架之UIView二的更多相关文章
- UIKit 框架之UIView一
- (id)initWithFrame:(CGRect)aRect //通过一个矩形对象初始化 Configuring a View’s Visual Appearance //配置视觉展示 @pro ...
- UIKit 框架之UITableView二
// // ViewController.m // UITableView // // Created by City--Online on 15/5/21. // Copyright (c) 201 ...
- UIKit框架使用总结--看看你掌握了多少
一.经常使用的,基本就是每次项目迭代都需要使用的 UIView.UILabel.UIImage.UIColor.UIFont.UIImageView.UITextField.UIButton. UIS ...
- UIKit框架
在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...
- iOS学习32之UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。
转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...
- iOS开发UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架
Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...
- UIKit 框架之Bar、Controller
UIKit框架中有各种Bar,UITabBar.UINavigationBar.UIToolbar.Bar对应的就有一些Item,tabBarItem.navigationItem.toolbarIt ...
随机推荐
- Swift3 今日(TodayExtension)扩展图文笔记
>图片1(创建今日扩展) >图片2 >图片3(设置大小) >图片4(绘画控件) >图片5(设置共享文件) >图片6(设置群组ID) >图片7(设置URL ...
- mysql 多个and的简写
select * from test where name='zj' and sex='2'; 我以前也经常用这种写法,今天爬出去看了一下某位人写的,用了一下也挺好用的 下面这种写法,一一对应关系
- Python 数据类型之一:列表(list)
本次内容主要是总结一下 Python 数据类型中的 list (列表),关于 list 我在 Python 学习第二章已经简单介绍过了,这次呢,我这边主要总结自己学到的跟大家分享一下,有什么不对或者更 ...
- Modeless对话框如何响应快捷键
MFC,Modeless对话框不会响应快捷键.解决的方案很多,其中之一是在PreTranslateMessage中地键盘消息进行拦截处理.
- 第二节:创建模型,使用Code First,配置映射关系
这一节,实现模型的创建,配置映射关系 使用Code First数据迁移. 创建模型 一,首先创建几个接口:实体接口,聚合根接口,值对象接口 1,实体接口: 2,聚合根接口: 3,值对象接口: 二,模型 ...
- 企业项目开发--cookie(1)
此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 注:本章代码基于<第五章 企业项目开发--mybatis注解与xml并用>的代码,链接如下: h ...
- Duolingo 提高用户留存率的6个手段
翻译 :马玉洁 欢迎访问网易云社区,了解更多网易技术产品运营经验. 如果你用过"Duolingo"(Duolingo)这个语言教育应用程序,你就会知道它就像一款游戏. 这当然不是巧 ...
- centos7----pstree
centos 默认没有pstree 安装 yum -y install psmisc
- pinnet 计算云分区
fdisk /dev/xvdemne mnlEnterEnter 9G-98G-98G-478M-28G-28G-28G mw #设置文件格式mkfs -t ext4 /dev/xvde5mkfs - ...
- iOS--各种bug详解
1.为什么传的参数都对,但是就是请求不下来数据. 答:检查下传的字符串中,是不是有多的空格. 例如: 错误:{"startIndex":"1","en ...