所有的UI控件都是UIView的子类
UIWindow
UIWindow是UIView的子类
1、创建和配置UIWindow
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
2、APPDelegate.m文件中各方法调用的情况
//开启循环机制
//程序启动完毕(创建UI控件,)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {}
//应用程序将要进入非活动状态(将要失去焦点,例如,来电)
- (void)applicationWillResignActive:(UIApplication *)application {}
//进入后台(保存数据,一定时间后会挂起)
- (void)applicationDidEnterBackground:(UIApplication *)application {}
//即将进入前台(恢复数据)
- (void)applicationWillEnterForeground:(UIApplication *)application {}
//进入活动状态
- (void)applicationDidBecomeActive:(UIApplication *)application {}
//程序退出前调用,(保存数据)
- (void)applicationWillTerminate:(UIApplication *)application {}
//内存警告,当应用程序内存过低时,会发出警告(清除不常用的内存,)
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{NSLog(@"内存警告");}
UIView
1.创建UIView
//代码创建
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,0,100,100)];
//xib创建
UIView *view = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil][0];\
2.常用属性
backgroundColor //背景色
subViews //子视图
hidden //是否隐藏
tag //标签值
superview //父视图
userInteractionEnabled //是否响应 户触摸事件
clipsToBounds //是否裁剪其 视图
3.常用方法
• insertSubview:atIndex: //视图插入到制定索引位置
• insertSubview:aboveSubview: //视图插 到指定视图之上
• insertSubview:belowSubview: //视图插 到指定视图之下
• bringSubviewToFront: //视图移动到最上层
• sendSubviewToBack: //视图移动到最底层
• exchangeSubviewAtIndex:withSubviewAtIndex //把两个索引对应视图交换位置
• removeFromSuperview //把视图从 视图中移除
• addSubview: //添加子视图 addSubview时,会对视图进 retain,需要及时释放 removeFromSuperview时会对视图进 释放
4.视图的简单动画
1.开始动画
+(void)beginAnimations:(NSString *)animationID context:(void *)context;
2.持续时间
+(void)setAnimationDuration:(NSTimeInterval)dur;
3.提交动画
+(void)commitAnimations
基于block的简单动画效果实现
+ (void)animateWithDuration:(NSTimeInterval)duration animations: (void (^)(void))animations completion:(void (^)(BOOL finished))completion