UIView、UIViewLayout UI_01
若学习比较吃力,可以先学习一下基础:@interface
AppDelegate :
UIResponder
<</span>UIApplicationDelegate>
(retain,
nonatomic)
UIWindow *window;
//将strong改成retain
[_window
release];———》可以写成self.window = nil;
//省掉释放和指向nil两步
[super
dealloc];
*)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
//创建应用程序的窗口,self.Window
是本应用窗口对象,重要作用将内容呈现给用户
//UIScreen 屏幕类,[UIScreen mainScreen]获取主屏幕,[UIScreen mainScreen]
bounds]获取主屏幕的大小
//UIColor 颜色类
self.window
= [[[UIWindow
alloc]
initWithFrame:[[UIScreen
mainScreen]
bounds]
]autorelease];
//对于屏幕上看到的内容都是UIView及UIView的子类
//UIView代表屏幕上的一块矩形区域
//如果屏幕上绘制出一块矩形区域,需要知道屏幕左上角坐标,即屏幕坐标系原点,还有矩形的宽和高

3、 快速创建出结构体变量分四步:
CGRect (位置,大小)
--------CGRectMake();
CGPoint(点)
--------CGPointMake();
CGSize(大小)
--------CGSizeMake();

//1.创建UIView
对象
UIView
*redView = [[UIView
alloc]initWithFrame:CGRectMake(50,
50,
100,
100)];
//3.修改视图的背景颜色,默认颜色是透明色
[redView
setBackgroundColor:[UIColor
redColor]];
//4.添加到父视图上——即添加在板报上
[self.window
addSubview:redView];
//2.释放所有权
[redView
release];
练习1创建一个绿色视图,添加到self.window上
UIView
*greenView =[[UIView
alloc]initWithFrame:CGRectMake(150,
50,
100,
100)];
[greenView
setBackgroundColor:[UIColor
greenColor]];
[self.window
addSubview:greenView];
[greenView release];

CGRect
newRect = [[UIScreen
mainScreen]
bounds];
//将结构体变量转为字符串对象输出
//NSStringFromCGRect()
//NSStringFromCGPoing()
//NSStringFromCGSize()
NSLog(@"%@",NSStringFromCGRect(newRect));
//建立内部绿色视图
// Override point for customization after application
launch.
//设置self.window.backgroundColor 的背景颜色
self.window.backgroundColor
= [UIColor
cyanColor];
//将self.window 设置为应用的主屏幕并使其可见
[self.window
makeKeyAndVisible];
return
YES;
//#pragma mark
-后面加一个-,表示在分组的基础上又进行了分块。
UIView 的重量级属性:frame center bounds
//center
:中心点,视图的中心点的坐标,相对于父视图坐标原点的位置
//center.x = frame.origin.x + frame.size.width / 2;
//center.y =
frame.origin.y + frame.size.width / 2;
//center 改变,frame也变 ,frame改变,center 也改变
//bounds,
一个视图的边界,CGRect(origin,size),origin是矩形区域所占的相对于自身坐标系的原点位置,size是矩形区域的大小,一个视图创建出来后默认bounds的origin的位置和自身视图的原点是重合的;bounds的(size)大小和frame的(size)大小是一样的;修改一个视图的bounds
的origin(x,y)的时候,视图的frame不变,center也不变;修改一个视图的size,frame变化,center不变;
//修改bounds
的origin的影响的自身原点的坐标位置,也既是影响自身子视图的位置
7、#pragma
mark 修改一个视图的Frame
//redView
UIView
*redView = [[UIView
alloc]initWithFrame:CGRectMake(60,
184,
200,
200)];
//定义一个矩形的结构体变量
//
CGRect rect = CGRectMake(100, 100, 100, 200);
//
redView.frame = rect;
//视图的frame不能被单个修改,只能整体赋值
//
redView.frame.origin.x = 100;
//
CGRect rect1 = redView.frame;
//
rect1.origin.x = 100;
//
rect1.origin.y = 100;
//
redView.frame = rect1;
8、#pragma mark
修改一个视图的senter
//
NSLog(@"%@",NSStringFromCGPoint(redView.center));
//
CGPoint center = CGPointMake(100, 100);
//
redView.center = center;
//
NSLog(@"%@",NSStringFromCGRect(redView.frame));
9、#pragma mark
修改一个视图的bounds
//
redView.bounds = CGRectMake(0, 0, 200, 200);
//
NSLog(@"%@",NSStringFromCGRect(redView.bounds));
redView.backgroundColor
= [UIColor
redColor];
[self.window
addSubview:redView];
[redView
release];
//greenView
UIView
*greenView = [[UIView
alloc]initWithFrame:CGRectMake(110,
234,
100,
100)];
greenView.backgroundColor
= [UIColor
greenColor];
[self.window
addSubview:greenView];
[greenView
release];
//blueView
UIView
*blueView = [[UIView
alloc]initWithFrame:CGRectMake(85,
209,
150,
150)];
blueView.backgroundColor
= [UIColor
blueColor];
[self.window
addSubview:blueView];
[blueView
release];
调整视图关系的方法1
aboveSubview:
B
在B视图上插入A视图
[self.window insertSubview:greenView
aboveSubview:blueView];

//insertSubview:A
belowSubview:B 在B视图下插入A视图
[self.window insertSubview:blueView
belowSubview:greenView];

//insertSubview:A atIndex:下标
将A视图添加到指定位置
[self.window
insertSubview:greenView
atIndex:2];
//或者
[self.window insertSubview:blueView atIndex:1];

//调整视图关系的方法2
1、//bringSubviewToFront:A
. 将A调整到所有子视图的最前面
[self.window
bringSubviewToFront:redView];

. 将A调整到所有子视图的最后面
[self.window
sendSubviewToBack:redView];
//exchangeSubviewAtIndex:下标1
withSubviewAtIndex:下标2,交换两个指定位置的子视图
[self.window
exchangeSubviewAtIndex:1
withSubviewAtIndex:2];

//[A removeFromSuperview ]
A视图从父视图中移除
[blueView removeFromSuperview];

=================================================
总结:
视图的层级关系:
1.最后添加的子视图肯定在所有视图的最前面
2.子视图永远在父视图的前面
3.子视图的添加是有顺序的
4.父视图通过subviews 数组管理所有的子视图
5.如果想调整视图之间的层级关系,需要通过父视图来调整
6.如果想从父视图中移除,使用将要移除的对象来调用方法
=============================================
12、定时器
//第一个参数 设置每过多长时间执行一次定时操作
//第二参数 有谁来执行操作
//第三个参数 选择执行的操作
//第四个参数 用户信息 nil
//第五个参数 是否需要重复定义器操作
[NSTimer
scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(printHelloword)
userInfo:nil
repeats:YES];
//以上程序结束
self.window.backgroundColor
= [UIColor
whiteColor];
[self.window
makeKeyAndVisible];
return
YES;
-
(void)printHelloword{
NSLog(@"你好");

15*(1 + 0)
290- 15*2*0
538- 15*2*0
15*(1 + 1)
290- 15*2*1
538- 15*2*1
15*(1 + 2)
290- 15*2*2
538- 15*2*2
15*(1 + 3)
290- 15*2*3
538- 15*2*3
15*(1 + 4)
290- 15*2*4
538- 15*2*4
15*(i+1)
290 - i*15*2
538 - i*15*2)
"AppDelegate.h"
AppDelegate
()
AppDelegate
- (void)dealloc
{
self.window
=
nil;
[super
dealloc];
*)application
didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
self.window
=
[[UIWindow
alloc]
initWithFrame:[[UIScreen
mainScreen]
bounds]];
//
Override point for customization after application
launch.
self.window.backgroundColor
=
[UIColor
whiteColor];
[self.window
makeKeyAndVisible];
————————————————————————————
for
(int
i
= 0;
i <</span> 10;
i ++) {
UIView
*view
= [[UIView
alloc]initWithFrame:(CGRectMake(15*(i+1),15*(i+1),
290
-
i*15*2,
538
-
i*15*2))];
[self.window
addSubview:view];
view.backgroundColor
=
[UIColor
colorWithRed:kColorValue
green:kColorValue
blue:kColorValue
alpha:1];
view.tag
=
100+i;
[view release];
}
[NSTimer
scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(fromOutToInside)
userInfo:nil
repeats:YES];
return
YES;
(void)fromOutToInside{
UIColor
*temp
= [self.window
viewWithTag:100
+
9].backgroundColor;
for
(int
i
= 100
+
9;
i >= 100;
i--) {
[self.window
viewWithTag:i].backgroundColor
=
[self.window
viewWithTag:i-1].backgroundColor;
}
[self.window
viewWithTag:100].backgroundColor
=
temp;
—————————————————————————————————————————————
UIView、UIViewLayout UI_01的更多相关文章
- [BS-26] UIView、pop和Core Animation区别
UIView.pop和Core Animation区别 一.UIView.pop和Core Animation的主要区别 1. Core Animation的动画只能添加到layer上(layer.p ...
- ios基础篇(二十五)—— Animation动画(UIView、CoreAnimation)
Animation主要分为两类: 1.UIView属性动画 2.CoreAnimation动画 一.UIView属性动画 UIKit直接将动画集成到UIView类中,实现简单动画的创建过程.UIVie ...
- 有关UIView、subview的几个基础知识点-IOS开发 (实例)
环境是xcode4.3 首先要弄懂几个基本的概念. 一)三个结构体:CGPoint.CGSize.CGRect 1. CGPoint /* Points. */ struct CGPoint { C ...
- iOS:UIView、UIControl、UIButton、UILabel简单的属性和方法常识
常见属性和方法 一 .UIVIew 常见属性 1.frame 位置和尺寸(以父控件的左上角为原点(0,0)) 2.center 中点 (以父控件的左上角为原点(0,0)) 3.bounds 位置和尺寸 ...
- iOS开发系列--触摸事件、手势识别、摇晃事件、耳机线控
-- iOS事件全面解析 概览 iPhone的成功很大一部分得益于它多点触摸的强大功能,乔布斯让人们认识到手机其实是可以不用按键和手写笔直接操作的,这不愧为一项伟大的设计.今天我们就针对iOS的触摸事 ...
- 你真的了解UIEvent、UITouch吗?
一:首先查看一下关于UIEvent的定义 //事件类型 typedef NS_ENUM(NSInteger, UIEventType) { UIEventTypeTouches, UIEventTyp ...
- 详解CALayer 和 UIView的区别和联系
详解CALayer 和 UIView的区别和联系 前言 前面发了一篇iOS 面试的文章,在说到 UIView 和 CALayer 的区别和联系的时候,被喵神指出没有切中要点,所以这里就 CALay ...
- iOS-触摸事件、手势识别、摇晃事件、耳机线控
概览 iPhone的成功很大一部分得益于它多点触摸的强大功能,乔布斯让人们认识到手机其实是可以不用按键和手写笔直接操作的,这不愧为一项伟大的设计.今天我们就针对iOS的触摸事件(手势操作).运动事件. ...
- iOS - UIView
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIView : UIResponder <NSCoding, UIAppearance, UIAppeara ...
随机推荐
- Oracle中建库时报Exception in thread main
Linux操作系统上安装oracle 10g,在启动dbca的时候报 Exception in thread "main" 错误,详细内容如下: [oracle@centos ~] ...
- Node.js 虚拟机
稳定性: 3 - 稳定 可以通过以下方法访问该模块: var vm = require('vm'); JavaScript 可以立即编译立即执行,也可以编译,保存,之后再运行. vm.runInThi ...
- jQuery 效果 – 滑动
jQuery 滑动方法可使元素上下滑动. 点击这里,隐藏/显示面板 一寸光阴一寸金,因此,我们为您提供快捷易懂的学习内容. 在这里,您可以通过一种易懂的便利的模式获得您需要的任何知识. 实例 jQue ...
- k8s Kubernetes v1.10
#转移页面 http://www.cnblogs.com/elvi/p/8976305.html
- Android开发学习之路--性能优化之常用工具
android性能优化相关的开发工具有很多很多种,这里对如下六个工具做个简单的使用介绍,主要有Android开发者选项,分析具体耗时的Trace view,布局复杂度工具Hierarchy Vie ...
- 计算机网络之文件传送协议FTP
FTP 文件传送协议FTP(File Transfer Protocol)是因特网上使用最广泛的文件传送协议. FTP 提供交互式的访问,允许客户指明文件的类型与格式,并允许文件具有存取权限.FTP ...
- Objective-C特有类型——id
Objective-C特有类型--id OC里,id和int.double等一样,是一个类型 不同的是: id是一个万能指针,能指向/操作任何OC对象 相当于 (NSObject *) 用法 id i ...
- [code segments] OpenCV3.0 SVM with C++ interface
talk is cheap, show you the code: /***************************************************************** ...
- Python 妙用heapq
小顶堆求TopK大 大顶堆求BtmK小 题外话 Python有一个内置的模块,heapq标准的封装了最小堆的算法实现.下面看两个不错的应用. 小顶堆(求TopK大) 话说需求是这样的: 定长的序列,求 ...
- Thread 方法
Thread类的一些被Thread对象调用的方法: 1 public void start() 使该线程开始执行:Java 虚拟机调用该线程的 run 方法. 2 public void run() ...