zoukankan      html  css  js  c++  java
  • UIView视图层次

    #import "AppDelegate.h"

    @interface AppDelegate ()

    @end

    @implementation AppDelegate

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        // Override point for customization after application launch.

        

        

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

        self.window.backgroundColor = [UIColor whiteColor];

        [self.window makeKeyAndVisible];

        

        self.window.rootViewController = [[UIViewController alloc]init];

        

        UIView *backView = [[UIView alloc] initWithFrame:self.window.bounds];

        

        NSArray *color = @[[UIColor redColor],[UIColor yellowColor],[UIColor blueColor],[UIColor greenColor]];

        for (int i = 0; i<color.count; i++) {

            UIView *view =[[UIView alloc]initWithFrame:CGRectMake(50+40*i, 50+40*i, 200, 200)];

            view.backgroundColor = color[i];

            view.tag = 100+i;

            [backView addSubview:view];

            //[self.window addSubview:view];

            [view release];

            

        }

       

        NSLog(@"%@",backView.subviews);

        NSLog(@"===================");

        UIView *redView = [backView viewWithTag:100];

        //把视图移动到最高层

        //[backView addSubviewToFront:redView];

        

       [backView addSubview:redView];

        

        NSLog(@"%@",backView.subviews);

        

        UIView *greenView = [backView viewWithTag:103];

        //把视图移动到最顶层

        [backView sendSubviewToBack:greenView];

        

        

        

        

        UIView *yellowView = [backView viewWithTag:101];

        UIView *blueView = [backView viewWithTag:102];

        //交换两个视图的层次

        

        [backView exchangeSubviewAtIndex:[backView.subviews indexOfObject:yellowView] withSubviewAtIndex:[backView.subviews indexOfObject:blueView]];

        

        

        

        

        UIView *blackView = [[UIView alloc]initWithFrame:CGRectMake(180, 20, 20, 300)];

        

        

        

        //插入到指定的下标中

        [backView insertSubview:blackView atIndex:1];

        

        [backView release];

        

        

        //插入到指定视图的上面

        [blackView insertSubview:blackView aboveSubview:yellowView];

        

        

        [blackView release];

        

        //在父视图上移除子视图

        [blackView removeFromSuperview];

        NSLog(@"%@",blackView.subviews);

        

        return YES;

    }

  • 相关阅读:
    设计模式---行为变化模式之命令模式(Command)
    设计模式---数据结构模式之职责链模式(Chain of Responsibility)
    设计模式---数据结构模式之迭代器模式(Iterate)
    WinCE全屏手写输入法
    .net下所有DLL(API)查询,转换C#代码
    在线cron表达式生成器
    完全卸载vs2013、vs2015的方法
    java微信 客服接口-发消息 中文乱码
    【路由达人】简单两步搞定小米路由新增功能-DDNS(解析域名地址转向在线工具)
    微信公众平台开发入门教程
  • 原文地址:https://www.cnblogs.com/chunji/p/5257441.html
Copyright © 2011-2022 走看看