窗口、视图、动画(16.5.20)
来源:互联网 发布:hp1005扫描软件打不开 编辑:程序博客网 时间:2024/06/05 17:56
UIWindow
1.特点
一个窗口包含多个视图,APP只有一个UIWindow,UIWindow是APP的的根容器;
通过UIApplication获取当前window,UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
窗口的大小是手机屏幕的大小;
自定义窗口:
self.window = [[UIWindow alloc] initWithFrame[UIScreen mainScreen] bounds];
[self.window makeKeyAndVisible]//显示窗口
Xcode6.0以后工程自动创建了窗口。
视图属性:
视图的位置和大小是用frame和bound来表示;
frame以其父视图为起点,得出自己在父视图的大小和位置;
bound以自身为起点,指定自身大小和原点位置,坐标永远是(0,0),它是结构体,和frame一样。
center以父视图为起点,得出自己的中点在父视图坐标系中的位置,它也是结构体。有两个成员x、y轴。
frame改变时,bouds和center也改变;
center改变时,frame的origin改变。
//创建一个视图并把它贴到根视图控制器的view上
UIView *aView = [[UIViewalloc] initWithFrame:CGRectMake(0, 0,100, 100)];
aView.backgroundColor = [UIColoryellowColor];
[self.viewaddSubview:aView];//添加子视图
[aView release];
// return;
//创建一个视图并把它贴到根视图控制器的view上
UIView *aView3 = [[UIViewalloc] initWithFrame:CGRectMake(0, 0, 120, 120)];
aView3.backgroundColor = [UIColorredColor];
[self.viewaddSubview:aView3];
[self.viewinsertSubview:aView aboveSubview:aView3];//aView插入aView3之上
[aView3 release];
// return;
//创建一个视图并把它贴到根视图控制器的view上
UIView *aView4 = [[UIViewalloc] initWithFrame:CGRectMake(0, 0, 160, 160)];
aView4.backgroundColor = [UIColorgreenColor];
[self.viewaddSubview:aView4];
[self.viewinsertSubview:aView4 belowSubview:aView3];//aView4插入aView3之下
[aView4 release];
// return;
//建一个视图并把它贴到根视图控制器的view上
UIView *aView5 = [[UIViewalloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
aView5.backgroundColor = [UIColorgrayColor];
[self.viewaddSubview:aView5];
[self.viewsendSubviewToBack:aView5];//把aView5移动到所有子视图下面
[aView5 release];
// return;
[self.viewbringSubviewToFront:aView3];//把aView3移动到所有子视图上面
[aView5 removeFromSuperview];//视图aView5从父视图self.view中移除
UIView *aView = [[UIViewalloc] initWithFrame:CGRectMake(10, 100, 200, 200)];
[self.viewaddSubview:aView];
[aView release];
aView.backgroundColor = [UIColoryellowColor];//背景色,默认值为白色
// aView.alpha = 0.5;//透明度,默认值为1.0
// aView.hidden = NO;//是否隐藏,默认值为NO
// if (aView.superview == self.view)
// {
// NSLog(@"视图的父视图是self.view");
// }
//
// //视图tag的使用
// aView.tag = 666; //0~100已被系统占用,为避免与系统的tag冲突,最好600以上
// UIView *subView = [self.view viewWithTag:666];//通过tag值获取子视图
// if (subView)
// {
// subView.backgroundColor = [UIColor redColor];
// }
//
// aView.clipsToBounds = YES; //越界裁剪属性,默认值为NO
// UIView *aView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 100)];
// aView2.backgroundColor = [UIColor greenColor];
// [aView addSubview:aView2];
// [aView2 release];
// aView.userInteractionEnabled = YES; //是否接收用户触摸事件,默认值为YES
NSArray *array =self.view.subviews;
NSLog(@"%@", array);
UIView *aView = [[UIViewalloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
aView.center = self.view.center;//窗口中心显示
aView.backgroundColor = [UIColorredColor];
[self.viewaddSubview:aView];
[aView release];
// 动画形式1
#if 0
[UIView beginAnimations:@"curl" context:nil];//开启动画
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//设置动画展现速度
[UIView setAnimationDuration:1.0];//设置动画持续时间
// [UIView setAnimationDelay:2];//延缓2秒后执行动画(默认不延缓)
[UIView setAnimationDelegate:self];//设置动画委托
[UIView setAnimationDidStopSelector:@selector(animationFinished)];//设置动画结束后的回调(与委托delegate绑定使用)
// CGRect rect = aView.frame;
aView.frame = CGRectMake(0, 0, 30, 30);
aView.center = self.view.center;//窗口中心显示
// aView.frame = CGRectMake(rect.origin.x, 250, rect.size.width, rect.size.height);
// aView.alpha = 0.0;
aView.backgroundColor = [UIColor yellowColor];
[UIView commitAnimations];// 提交动画
#endif
//动画形式2
#if 0
[UIView animateWithDuration:2.0 animations:^{
// CGRect rect = aView.frame;
// aView.frame = CGRectMake(rect.origin.x, rect.origin.y, 30, 30);
// aView.frame = CGRectMake(rect.origin.x, 250, rect.size.width, rect.size.height);
// aView.alpha = 0.0;
// aView.backgroundColor = [UIColor yellowColor];
}];
#endif
//动画形式3
#if 0
[UIView animateWithDuration:2.0 animations:^{
// CGRect rect = aView.frame;
// aView.frame = CGRectMake(rect.origin.x, rect.origin.y, 30, 30);
// aView.frame = CGRectMake(rect.origin.x, 250, rect.size.width, rect.size.height);
// aView.alpha = 0.0;
aView.backgroundColor = [UIColor yellowColor];
} completion:^(BOOL finished) {
NSLog(@"动画结束了");
}];
#endif
//动画形式4
#if 0
[UIView animateWithDuration:2.0 delay:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
// CGRect rect = aView.frame;
// aView.frame = CGRectMake(rect.origin.x, rect.origin.y, 30, 30);
// aView.frame = CGRectMake(rect.origin.x, 250, rect.size.width, rect.size.height);
// aView.alpha = 0.0;
aView.backgroundColor = [UIColor yellowColor];
} completion:^(BOOL finished) {
NSLog(@"动画结束了");
}];
#endif
//视图的仿射变换
#if 1
[UIView animateWithDuration:2.0 animations:^{
// aView.transform = CGAffineTransformMakeScale(1.0, 0.5);//对视图进行比例缩放(比如:缩小到原来的0.5倍)
aView.transform =CGAffineTransformMakeRotation(M_PI/4);//对视图做变焦旋转,旋转45度
// aView.transform = CGAffineTransformMakeTranslation(0, 100);//对视图在原来的位置上做平移
} completion:^(BOOL finished) {
NSLog(@"~~~~~动画结束了~~~~~");
}];
#endif
//组合动画
#if 1
[UIView animateWithDuration:2.0 animations:^{
CGAffineTransform newTransform =CGAffineTransformMakeScale(1.5, 1.5);
[aView setTransform:newTransform];
} completion:^(BOOL finished) {
NSLog(@"动画1结束了,开始动画2");
[UIView animateWithDuration:2.0 animations:^{
CGAffineTransform newTransform =CGAffineTransformMakeScale(0.5, 0.5);
[aView setTransform:newTransform];
} completion:^(BOOL finished) {
NSLog(@"动画2结束了,开始动画3");
[UIViewanimateWithDuration:2.0 animations:^{
aView.backgroundColor = [UIColorbrownColor];
} completion:^(BOOL finished) {
NSLog(@"动画3结束了,开始动画4");
[UIViewanimateWithDuration:2.0 animations:^{
aView.alpha = 0.0;
} completion:^(BOOL finished) {
NSLog(@"动画4结束了,开始动画5");
[UIViewanimateWithDuration:2.0 animations:^{
aView.alpha = 1.0;
} completion:^(BOOL finished) {
NSLog(@"动画5结束了,开始动画6");
[UIViewanimateWithDuration:2.0 animations:^{
aView.transform = CGAffineTransformMakeRotation(M_PI/2);
} completion:^(BOOL finished) {
NSLog(@"动画6结束了,开始动画7");
[UIView animateWithDuration:2.0 animations:^{
aView.transform =CGAffineTransformMakeRotation(M_PI);
} completion:^(BOOL finished) {
NSLog(@"动画7结束了,完了");
}];
}];
}];
}];
}];
}];
}];
#endif
//动画结束后的回调方法
- (void)animationFinished
{
NSLog(@"动画结束了");
}
- 窗口、视图、动画(16.5.20)
- Android动画(2)视图动画
- Android View动画(视图动画)
- Android动画(一)-视图动画
- 视图动画(View Animation)
- View Animation(视图动画)
- Android动画学习-视图动画&属性动画(一)
- Android动画学习-视图动画&属性动画(二)
- 视图动画
- 视图动画
- 视图动画
- 视图动画
- Android动画--视图动画
- 【动画系列】视图动画
- 动画窗口
- 单文档多视图(分割窗口)
- 单文档多视图(分割窗口)
- UIWindow :窗口 (UIView) UIView: 视图
- SVN系列(一)--SVN版本控制原理
- 高效地配置OkHttp
- php操作redis常用方法
- Core Animation - 图层行为
- OKHTTP3 Version=2.4.1 编码问题
- 窗口、视图、动画(16.5.20)
- 对象检测之行人检测(2)
- C++第6次实验
- C++第六次实验
- sql性能相关语句
- rpm安装mysql过程
- Android网络编程——https 不验证证书方式(信任所有证书)
- 文章标题
- Javascript弹出层