zoukankan      html  css  js  c++  java
  • 如何根据父视图大小变化改变子视图大小变化(autoresizingMask)

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        UIView *v=[[UIView alloc]initWithFrame:CGRectMake(50, 50, 200, 200)];
        v.backgroundColor=[UIColor redColor];
        v.tag=100;
        [self.view addSubview:v];
        UIView *v1=[[UIView alloc]initWithFrame:CGRectMake(20, 20, 160, 160)];
        v1.backgroundColor=[UIColor blueColor];
        v1.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
        [v addSubview:v1];
        UIView *v2=[[UIView alloc]initWithFrame:CGRectMake(20, 20, 120, 120)];
        v2.backgroundColor=[UIColor yellowColor];
        v2.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
        [v1 addSubview:v2];
        UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
        [btn setTitle:@"缩小" forState:UIControlStateNormal];
        btn.frame=CGRectMake(50, 400, 70, 40);
        [self.view addSubview:btn];
        [btn addTarget:self action:@selector(doSomething) forControlEvents:UIControlEventTouchUpInside];
        UIButton *btn2=[UIButton buttonWithType:UIButtonTypeRoundedRect];
        [btn2 setTitle:@"放大" forState:UIControlStateNormal];
        btn2.frame=CGRectMake(250, 400, 70, 40);
        [self.view addSubview:btn2];
        [btn2 addTarget:self action:@selector(suoxiao) forControlEvents:UIControlEventTouchUpInside];
    }
    
    -(void)doSomething{
        UIView *v=[self.view viewWithTag:100];
    //    v.center=CGPointMake(200, 300);
        v.frame=CGRectMake(100, 200, 150, 150);
    }
    -(void)suoxiao{
        UIView *v=[self.view viewWithTag:100];
    //    v.center=CGPointMake(50, 50);
        v.frame=CGRectMake(50, 50, 200, 200);
    }
    
  • 相关阅读:
    VIM
    函数指针
    《BOOST程序库完全开发指南》 第13章 编程语言支持
    《BOOST程序库完全开发指南》 第01章 Boost程序库总论
    gtest
    《BOOST程序库完全开发指南》 第04章 实用工具
    distcc配置
    《BOOST程序库完全开发指南》 第08章 算法
    Makefile
    《BOOST程序库完全开发指南》 第03章 内存管理
  • 原文地址:https://www.cnblogs.com/amoy888/p/3483456.html
Copyright © 2011-2022 走看看