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);
    }
    
  • 相关阅读:
    函数与宏定义实验报告
    C语言作业3
    循环结构课后反思
    C语言作业2
    C程序设计实验报告
    百分制成绩五级分制输出--二次作业
    第九章 结构体与共用体
    第八章 指针实验
    第七章 数组实验
    第六章 函数和宏定义实验(2)
  • 原文地址:https://www.cnblogs.com/amoy888/p/3483456.html
Copyright © 2011-2022 走看看