// // CPDFImagePreview.m // PDFViewer // // Created by kdan on 2022/11/18. // #import "CPDFImagePreview.h" #import "Masonry.h" BOOL gImagePreviewIsFirstLayout = YES; @implementation CPDFImagePreview - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { _watermarkView = [[UIImageView alloc] init]; _rotationBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _documentView = [[UIImageView alloc] init]; [self addSubview:_documentView]; [_documentView addSubview:_watermarkView]; [_watermarkView addSubview:_rotationBtn]; } return self; } - (void)layoutSubviews { [super layoutSubviews]; _watermarkView.layer.borderColor = UIColor.blueColor.CGColor; _watermarkView.layer.borderWidth = 1; [_watermarkView sizeToFit]; _watermarkView.contentMode = UIViewContentModeScaleAspectFit; if (gImagePreviewIsFirstLayout) { CGRect frame = _watermarkView.frame; frame.origin = CGPointMake(_documentView.bounds.size.width / 2 - _watermarkView.frame.size.width / 2, _documentView.bounds.size.height / 2 - _watermarkView.frame.size.height / 2); _watermarkFrame = frame; gImagePreviewIsFirstLayout = NO; } _watermarkView.frame = _watermarkFrame; [_rotationBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(_watermarkView.mas_bottom).offset(-10); make.width.equalTo(@20); make.height.equalTo(@20); make.left.equalTo(_watermarkView.mas_right).offset(-10); }]; _rotationBtn.layer.cornerRadius = 10; _rotationBtn.layer.masksToBounds = YES; _rotationBtn.layer.borderColor = UIColor.blueColor.CGColor; [_rotationBtn setBackgroundImage:[UIImage imageNamed:@"btn_selected"] forState:UIControlStateNormal]; } @end