UIView

1.防止子视图响应父视图的手势


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if (self.contentView) {
        if ([touch.view isDescendantOfView:self.contentView]) {
            return NO;
        }
    }
    return YES;
}

2.animate动画

使用frame

[UIView animateWithDuration:0.1 animations:^{
    view.frame = tempFrame;
} completion:^(BOOL finished) {
    if (finished) {
        otherView.hidden = YES;
    }
}];

使用constraints

[self updateConstraintsIfNeeded];//必要
[UIView animateWithDuration:0.3 animations:^{
    //update:改变已有的或者创建一个新的;remake:全部重写
    [view mas_updateConstraints:^(MASConstraintMaker *make) {
        make_left_equalTo(self.mas_left).offset(10);
    }];
    [self layoutIfNeeded];//必要
} completion:^(BOOL finished) {
    
}];

3.父视图改变frame导致子视图改变frame

解决:

superview.autoresizeSubviews = NO;

4.设置阴影

//设置背景色,否则该view本身不会有阴影(应该是因为默认透明),其所有的subviews会有阴影
_overviewView.layer.backgroundColor = [UIColor whiteColor].CGColor;
//设置阴影的颜色
_overviewView.layer.shadowColor = [UIColor blackColor].CGColor;
//设置偏移量,x轴、y轴,默认x=0,y=-3
_overviewView.layer.shadowOffset = CGSizeMake(0, 1);
//设置阴影的透明度
_overviewView.layer.shadowOpacity = 0.2;
//设置阴影大小
_overviewView.layer.shadowRadius = 3;

5.子视图超出父视图的显示范围

superView.clipsToBounds = YES;//子视图超出父视图范围部分不显示

你可能感兴趣的:(UIView)