美文网首页
iOS xib 更改frame

iOS xib 更改frame

作者: yuezishenyou | 来源:发表于2018-04-13 18:35 被阅读0次

// 动态更改frame


- (void)show
{
    CGFloat width = [[UIScreen mainScreen]bounds].size.width;
    
    CGFloat height = [[UIScreen mainScreen]bounds].size.height;
    
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    /**
     * tbView 在这个view里高约束是200
                                 目标把高改为500
     */

    
    self.bgBtn.alpha = 0;
    self.tbView.frame = CGRectMake(0, height, width, 500);
    [self setNeedsLayout];
    [self layoutIfNeeded];
    
    [UIView animateWithDuration:.3f animations:^{
        self.bgBtn.alpha = 0.3f;
        self.tbView.frame = CGRectMake(0, height - 500, width, 500);
    } completion:^(BOOL finished) {
        
    }];
}

- (void)dismiss
{
    CGFloat width = [[UIScreen mainScreen]bounds].size.width;
    
    CGFloat height = [[UIScreen mainScreen]bounds].size.height;
    
    [UIView animateWithDuration:0.3 animations:^{
    
        self.bgBtn.alpha = 0;
        self.tbView.frame = CGRectMake(0, height, width, 400);
        
    } completion:^(BOOL finished) {
    
        [self removeFromSuperview];
    }];
}

// Masonry 更改frame

        [self setNeedsUpdateConstraints];
        [UIView animateWithDuration:0.3 animations:^{
            
            //NSInteger height = kCellHeight * 2 + 60 + 60;
            [self mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.supView).with.offset(5);
                make.right.equalTo(self.supView).with.offset(-5);
                make.bottom.equalTo(self.supView).with.offset(-5);
                make.height.mas_offset(240);
            }];
            [self.superview layoutIfNeeded];
            
        }];

相关文章

网友评论

      本文标题:iOS xib 更改frame

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