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;//子視圖超出父視圖范圍部分不顯示