UIView

1.防止子視圖響應(yīng)父視圖的手勢

<UIGestureRecognizerDelegate>
- (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:改變已有的或者創(chuàng)建一個新的;remake:全部重寫
    [view mas_updateConstraints:^(MASConstraintMaker *make) {
        make_left_equalTo(self.mas_left).offset(10);
    }];
    [self layoutIfNeeded];//必要
} completion:^(BOOL finished) {
    
}];

3.父視圖改變frame導(dǎo)致子視圖改變frame

解決:

superview.autoresizeSubviews = NO;

4.設(shè)置陰影

//設(shè)置背景色,否則該view本身不會有陰影(應(yīng)該是因為默認(rèn)透明),其所有的subviews會有陰影
_overviewView.layer.backgroundColor = [UIColor whiteColor].CGColor;
//設(shè)置陰影的顏色
_overviewView.layer.shadowColor = [UIColor blackColor].CGColor;
//設(shè)置偏移量,x軸、y軸,默認(rèn)x=0,y=-3
_overviewView.layer.shadowOffset = CGSizeMake(0, 1);
//設(shè)置陰影的透明度
_overviewView.layer.shadowOpacity = 0.2;
//設(shè)置陰影大小
_overviewView.layer.shadowRadius = 3;

5.子視圖超出父視圖的顯示范圍

superView.clipsToBounds = YES;//子視圖超出父視圖范圍部分不顯示
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容