原有工具栏功能的实现是一个自定义的UIView,但最近的新需求是根据用户的不同身份,给这个自定义的view添加不同的边框,如图:

用户身份6种,根据不同的身份展示不同的边框,边框图片是UI已经做好了的
经过尝试,设置背景图的效果时候,边框会被遮盖
只有将背景框的图片遮盖在原有的自定义view上展示效果才比较理想
但是遇到了一个问题,就是当背景框的图片遮住了原有的UIView之后,会导致UIView上的所有按钮和tap手势都接收不到点击事件.
解决方案和步骤:
1.创建一个UIImageView的子类YZClearImageView
.m
#import "YZClearImageView.h"
@implementation YZClearImageView
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView * hitView = [super hitTest:point withEvent:event];
if (hitView == self) {
return nil;
}
return hitView;
}
@end
.h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface YZClearImageView : UIImageView
@end
NS_ASSUME_NONNULL_END
2.设置imageView的用户交互和frame
self.imageView = [[YZClearImageView alloc] initWithFrame:frame];
self.imageView.backgroundColor = [UIColor clearColor];
self.imageView.image = [UIImage imageNamed:@"YZ_img_gzkp_wz"];
self.imageView.userInteractionEnabled = YES;
self.imageView.center = self.contentView.center;
[self addSubview:self.imageView];
网友评论