美文网首页
iOS autoresizingMask使用

iOS autoresizingMask使用

作者: Young_Blood | 来源:发表于2016-07-01 11:40 被阅读273次
    /*
     UIViewAutoresizingNone                 = 0,      /// 不随父视图的改变而改变
     UIViewAutoresizingFlexibleLeftMargin   = 1 << 0, /// 自动调整view与父视图左间距,保证右间距不变
     UIViewAutoresizingFlexibleWidth        = 1 << 1, /// 自动调整view的宽度,保证左间距和右间距不变
     UIViewAutoresizingFlexibleRightMargin  = 1 << 2, /// 自动调整view与父视图右间距,以保证左间距不变
     UIViewAutoresizingFlexibleTopMargin    = 1 << 3, /// 自动调整view与父视图上间距,以保证下间距不变
     UIViewAutoresizingFlexibleHeight       = 1 << 4, /// 自动调整view的高度,以保证上间距和下间距不变
     UIViewAutoresizingFlexibleBottomMargin = 1 << 5  /// 自动调整view与父视图的下间距,以保证上间距不变
     */
    

    测试代码如下

    - (void)viewDidLoad {
        [super viewDidLoad];
        
        UIView *redView = [[UIView alloc] init];
        self.redView = redView;
        [self.view addSubview: redView];
        redView.frame = CGRectMake(100, 100, 300, 300);
        redView.backgroundColor = [UIColor redColor];
        
        UIView *blueView = [[UIView alloc] init];
        [redView addSubview:blueView];
        blueView.backgroundColor = [UIColor blueColor];
        blueView.frame = CGRectMake(50, 50, 100, 100);
        blueView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
        
        
        NSLog(@"%ld",self.view.autoresizingMask);
        NSLog(@"---%d",1 << 1 | 1 << 4);
    }
    
    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        CGRect f = self.redView.frame;
        f.size.width +=5;
        f.size.height +=5;
        self.redView.frame = f;
    }
    
    

    相关文章

      网友评论

          本文标题:iOS autoresizingMask使用

          本文链接:https://www.haomeiwen.com/subject/oibfjttx.html