改变父view高度,子view同时隐藏

需要设置父view的 clipsToBounds = YES
作用是 视图上的子视图,如果超出父视图的部分就截取掉

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addviews];
}

- (void)addviews {
    mainview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
    [self.view addSubview:mainview];
    mainview.backgroundColor = [UIColor grayColor];

    //视图上的子视图,如果超出父视图的部分就截取掉,
    mainview.clipsToBounds = YES;
    
    UIView *sub1 = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 100, 100)];
    [mainview addSubview:sub1];
    sub1.backgroundColor = [UIColor yellowColor];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    CGRect frame = mainview.frame;
    [UIView animateWithDuration:2.0 animations:^{
        mainview.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, 10);
    }];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容