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 ...
随机推荐
- JavaScript基础知识从浅入深理解(一)
JavaScript的简介 javascript是一门动态弱类型的解释型编程语言,增强页面动态效果,实现页面与用户之间的实时动态的交互. javascript是由三部分组成:ECMAScript.DO ...
- Docker使用 Supervisor 来管理进程
Docker 容器在启动的时候开启单个进程,比如,一个 ssh 或者 apache 的 daemon 服务.但我们经常需要在一个机器上开启多个服务,这可以有很多方法,最简单的就是把多个启动命令放到一个 ...
- 毕业论文内容框架指导-适用于MIS系统
摘要: 背景.要做什么.选用什么技术.按照什么过程.原理.或者步骤去做.最后做出了什么东西.做出来的东西有什么用. 1. 前言 系统的背景与意义:为什么要做这个系统 ? 现状调查:别人做的怎么样? 系 ...
- Bootstrap3 代码-用户输入
通过 <kbd> 标签标记用户通过键盘输入的内容. To switch directories, type cd followed by the name of the directory ...
- cocos2dx 3.2之Lua打飞机项目
1 创建lua打飞机项目 cocos new T32Lua -dE:\Installed\cocos2d-x-3.2\cocos2d-x-3.2\projects -l lua 2 ...
- android galley实现画廊效果
青春流水指间. 每段路,都有即将要来的旅程 每颗心,都有值得期待的成分 Android之ImageSwitcher,Gallery用法 今天在做一个软件界面时用到了ImageSwitcher和Gall ...
- 有两个序列A和B,A=(a1,a2,...,ak),B=(b1,b2,...,bk),A和B都按升序排列。对于1<=i,j<=k,求k个最小的(ai+bj)。要求算法尽量高效。
有两个序列A和B,A=(a1,a2,...,ak),B=(b1,b2,...,bk),A和B都按升序排列.对于1<=i,j<=k,求k个最小的(ai+bj).要求算法尽量高效. int * ...
- Hibernate缓存集成IMDG
1 第三方缓存插件 除了Ehcache这种轻量级的缓存方案外,几乎所有IMDG产品都提供了对Hibernate二级缓存的直接支持,常用的有: Ø Hazelcast Ø GridGain Ø J ...
- 关于React Native 安卓首屏白屏优化
问题描述 在android中,当点击某个rn模块的入口按钮,弹出rn的activity到rn的页面展现出来的过程中,会有很明显的白屏现象,不同的机型不同(cpu好的白屏时间短),大概1s到2s的时间. ...
- Android透明动画
Android透明动画 核心方法 public void startAnimation(Animation animation) 执行动画,参数可以是各种动画的对象,Animation的多态,也可以是 ...