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);
    }
    
  • 相关阅读:
    9、二叉排序树的创建、插入、遍历
    8、判断两个链表是否相交
    7、判断链表是否有环
    6、查找单链表中倒数第n个节点
    5、单链表的反转
    4、KMP(看毛片)算法
    3、希尔排序
    2、快速排序
    json字符串转为json对象
    json对象转化为字符串过程分析
  • 原文地址:https://www.cnblogs.com/amoy888/p/3483456.html
Copyright © 2011-2022 走看看