1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- //
- // 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
|