CPDFImagePreview.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // CPDFImagePreview.m
  3. // PDFViewer
  4. //
  5. // Created by kdan on 2022/11/18.
  6. //
  7. #import "CPDFImagePreview.h"
  8. #import "Masonry.h"
  9. BOOL gImagePreviewIsFirstLayout = YES;
  10. @implementation CPDFImagePreview
  11. - (instancetype)initWithFrame:(CGRect)frame
  12. {
  13. if (self = [super initWithFrame:frame]) {
  14. _watermarkView = [[UIImageView alloc] init];
  15. _rotationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  16. _documentView = [[UIImageView alloc] init];
  17. [self addSubview:_documentView];
  18. [_documentView addSubview:_watermarkView];
  19. [_watermarkView addSubview:_rotationBtn];
  20. }
  21. return self;
  22. }
  23. - (void)layoutSubviews {
  24. [super layoutSubviews];
  25. _watermarkView.layer.borderColor = UIColor.blueColor.CGColor;
  26. _watermarkView.layer.borderWidth = 1;
  27. [_watermarkView sizeToFit];
  28. _watermarkView.contentMode = UIViewContentModeScaleAspectFit;
  29. if (gImagePreviewIsFirstLayout) {
  30. CGRect frame = _watermarkView.frame;
  31. frame.origin = CGPointMake(_documentView.bounds.size.width / 2 - _watermarkView.frame.size.width / 2, _documentView.bounds.size.height / 2 - _watermarkView.frame.size.height / 2);
  32. _watermarkFrame = frame;
  33. gImagePreviewIsFirstLayout = NO;
  34. }
  35. _watermarkView.frame = _watermarkFrame;
  36. [_rotationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.equalTo(_watermarkView.mas_bottom).offset(-10);
  38. make.width.equalTo(@20);
  39. make.height.equalTo(@20);
  40. make.left.equalTo(_watermarkView.mas_right).offset(-10);
  41. }];
  42. _rotationBtn.layer.cornerRadius = 10;
  43. _rotationBtn.layer.masksToBounds = YES;
  44. _rotationBtn.layer.borderColor = UIColor.blueColor.CGColor;
  45. [_rotationBtn setBackgroundImage:[UIImage imageNamed:@"btn_selected"] forState:UIControlStateNormal];
  46. }
  47. @end