• 如何根据父视图大小变化改变子视图大小变化(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);
    }
    
  • 相关阅读:
    图片文件重命名
    MySql基础学习-Sql约束
    MySql基础学习-库表操作
    java内存模型
    数据库常用函数整理
    linux用户管理
    Db2数据库在Linux下的安装和配置
    图像金字塔
    特征值与特征向量
    齐次线性方程组
  • 原文地址:https://www.cnblogs.com/amoy888/p/3483456.html
Copyright © 2020-2023  润新知