zoukankan      html  css  js  c++  java
  • 窗口与视图的基本概念

    一、UIWindow

    1.UIWindow和UIView的关系

    (1)UIWindow是UIView的一个子类,提供视图的显示区域;

    (2)UIWindow继承自UIView,包含应用程序的可视区域。

    2.UIWindow的创建

        //1.获取屏幕尺寸
        UIScreen *screen=[UIScreen mainScreen];
        CGRect rect=screen.bounds;
        //2.创建窗口,并铺满整个屏幕
        self.window=[[UIWindow alloc] initWithFrame:rect];
        //3.给窗口添加背景色
        self.window.backgroundColor=[UIColor colorWithRed:1.0 green:1.0 blue:0.0 alpha:1.0];
        //    self.window.backgroundColor=[UIColor whiteColor];
        //4.显示窗口
        [self.window makeKeyAndVisible];

    二、iOS坐标系统

    1.创建视图View

        //创建视图v0,v0作为UIWindow的子视图
        UIView *v0=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
        v0.backgroundColor=[UIColor blueColor];
        [self.window addSubview:v0];
        
        //创建视图v1,v1作为UIWindow的子视图
        UIView *v1=[[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
        v1.backgroundColor=[UIColor redColor];
        [self.window addSubview:v1];
        
        //创建视图v2,v2作为UIWindow的子视图
        UIView *v2=[[UIView alloc]initWithFrame:CGRectMake(150, 150, 200, 200)];
        v2.backgroundColor=[UIColor greenColor];
        [self.window addSubview:v2];

    2.frame、bounds、center的关系

    frame:表示视图在父视图的坐标系统里的位置和大小。

    bounds:表示视图在本身的坐标系统里的位置和大小。

    center:表示视图在父视图的坐标系统里的中点位 置。

    注:改变其中一个属性会影响其它两个。

        v2.frame = CGRectMake(0, 0, 200, 200);
    //  v1.center = CGPointMake(100, 100);
    //  v1.bounds = CGRectMake(0, 0, 200, 200);
    //  v1.frame = CGRectMake(200, 200, 10, 200);
  • 相关阅读:
    zoj 1671 Walking Ant【简单bfs】
    hdoj 2717 Catch That Cow【bfs】
    hdoj 1010 Tempter of the Bone【dfs查找能否在规定步数时从起点到达终点】【奇偶剪枝】
    poj 1321 棋盘问题【dfs】
    [LC] 124. Binary Tree Maximum Path Sum
    [LC] 113. Path Sum II
    [LC] 112. Path Sum
    [LC] 98. Validate Binary Search Tree
    [LC] 39. Combination Sum
    [LC] 159. Longest Substring with At Most Two Distinct Characters
  • 原文地址:https://www.cnblogs.com/hecheng0314/p/4409956.html
Copyright © 2011-2022 走看看