UI设计 创建视图

  /*

    ios:苹果移动设备的操作系统

    uikit:里面包含了所有可以看得见的视图空间

    UIwindow:窗口->IOS应用程序中 只能有一个主窗口  是用来显示承载   可以看到的控件的 容器-->所有的控件都是一层层 添加到窗口上的

      UIwindow:初始化 :     UIwindow *Uiwindow=[[UIWindow alloc]initWithFrame:<#(CGRect)#>];

      initWithFrame构造方法——>在创建一个对象的时候 同时给他一个frame

     获取屏幕边境范围:

     

     makeKeyAndVisible:让窗口是主窗口并且显示在屏幕上

     两种创建方式:

       1.       UIWindow *window=[[UIWindow alloc]initWithFrame:[UIScreen     mainScreen].bounds];

                                   [window makeKeyAndVisible];

     

      2.         self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

     [self.window makeKeyAndVisible];

=========================================================================

    Uiview:是一个视图------>是所有视图类的父类   uiwindow 也属于视图

   *****  1.视图的创建:UIView *view=[[UIView alloc]init]; 

               视图的位置和自身大小也是非常重要的   ( frame ---位置) 屏幕上 是有很多像素点组成的

     视图的起始位置:origin  

     窗口的起始位置是左上角(0,0)所有子视图都是根据 origin (原点,起始点) 来定义 起始位置的

     size--->尺寸  视图本身的大小   

     view1.frame=CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)设置位置

    设置透明度 0.0 (完全透明)----1.0(不透明)

    0.0情况下所有属性 方法 类似被禁用       view.alpha=0.5;

    隐藏 : hidden     view.hidden       view.hidden=YES; 表示隐藏     view.hidden=NO; 表示显示   默认不隐藏

     图层之间的关系:视图是一层层叠加到 一个父视图上的      

     父视图 :是一个承载体

     子视图:是父视图 里面的一元素

     父视图的位置发生改变  子视图 也会跟着 父视图位置一起改变

     frame :是根据他的父视图 来定义 这个视图自身位置的(原点)

     定义frame不要超出 父视图的范围  超出部分  将不会再接收任何响应的事件

     center:中心点   对角线的交点 (center.x=宽/2 + 原点的x         center.y=高/2+原点的y)

     改变中心点  可以改变 视图的位置  只能使用frame 在创建视图的时候 给他一个位置   

     相对于 自身的位置 原点永远是(0.0)bounds  自身的边境范围   bounds 用途   是获得视图的宽高 忽略 原点 

     

     定时器  隔多少秒  去做某件事  NSTimer 定时器的类

     初始化 方法:scheduledTimerWithTimeInterval:<#(NSTimeInterval)#> target:<#(nonnull id)#> selector:<#(nonnull SEL)#> userInfo:<#(nullable id)#> repeats:<#(BOOL)#>

     Nstimeinterval:时间间隔,单位是秒

     selector:方法选择器,用来选择一个方法去执行

    repeats:重复次数

    target:让谁执行

   *****   2.添加到父视图-->如果没有这个方法  创建的 视图将不会被显示在屏幕上{[self.window addSubview:view]; }

    */

    /* 创建窗口

     UIWindow *window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    [window makeKeyAndVisible];

    

    self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    [self.window makeKeyAndVisible];

    */

       self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

     [self.window makeKeyAndVisible];//创建一个主窗口 让他在屏幕上显示出来

    

    ViewController *vc=[[ViewController alloc]init];

    self.window.rootViewController=vc;

   

    self.window.backgroundColor =[UIColor  whiteColor];

    

    UIView *view1=[[UIView alloc ]initWithFrame:CGRectMake(100  ,100,  200, 200)];

    view1.backgroundColor=[UIColor cyanColor];

    [self.window addSubview:view1];

                                                            

    

    UIView *view2=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];

    view2.backgroundColor=[UIColor  orangeColor];

    [view1 addSubview:view2];

    

    NSLog(@" view1.center.x  x=%f",view1.center.x);

    

    view1.center=CGPointMake(150, 200);

    

    

    [NSTimer  scheduledTimerWithTimeInterval:1 target:self selector:@selector(start) userInfo:nil repeats:YES];


    /*

    UIView *view=[[UIView alloc]init];

    [self.window addSubview:view];

//    frame 是视图里面的一个属性

//    CGRect:

//    设置位置:

    view.frame=CGRectMake(0, 0, 200, 200);

//   背景颜色:

//    UIColor  ---》颜色类 ----》创建的对象就是一种颜色

    view.backgroundColor=[UIColor whiteColor];

   view.alpha=0.5;  // 设置透明度

    view.hidden=YES; //设置隐藏不隐藏  默认 不隐藏

*/

    return  YES;

}

-(void)start{


    NSLog(@"123156");

}


- (void)applicationWillResignActive:(UIApplication *)application {

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}


- (void)applicationWillEnterForeground:(UIApplication *)application {

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}


- (void)applicationDidBecomeActive:(UIApplication *)application {

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}


- (void)applicationWillTerminate:(UIApplication *)application {

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}


@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值