CPDFAnnotationBaseViewController.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // CPDFAnnotationBaseViewController.m
  3. // compdfkit-tools
  4. //
  5. // Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. #import "CPDFAnnotationBaseViewController.h"
  13. #import "CPDFAnnotationBaseViewController_Header.h"
  14. @interface CPDFAnnotationBaseViewController () <CPDFColorSelectViewDelegate, CPDFColorPickerViewDelegate, CPDFOpacitySliderViewDelegate>
  15. @end
  16. @implementation CPDFAnnotationBaseViewController
  17. #pragma mark - Initializers
  18. - (instancetype)initWithStyle:(CAnnotStyle *)annotStyle {
  19. if (self = [super init]) {
  20. self.annotStyle = annotStyle;
  21. }
  22. return self;
  23. }
  24. #pragma mark - ViewController Methods
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. // Do any additional setup after loading the view.
  28. self.titleLabel = [[UILabel alloc] init];
  29. self.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
  30. self.titleLabel.font = [UIFont systemFontOfSize:20];
  31. self.titleLabel.adjustsFontSizeToFitWidth = YES;
  32. [self.view addSubview:self.titleLabel];
  33. self.backBtn = [[UIButton alloc] init];
  34. self.backBtn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  35. [self.backBtn setImage:[UIImage imageNamed:@"CPDFAnnotationBaseImageBack" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  36. [self.backBtn addTarget:self action:@selector(buttonItemClicked_back:) forControlEvents:UIControlEventTouchUpInside];
  37. [self.view addSubview:self.backBtn];
  38. self.sampleView = [[CPDFAnnotationSampleView alloc] init];
  39. self.sampleView.backgroundColor = [UIColor whiteColor];
  40. self.sampleView.layer.borderColor = [UIColor purpleColor].CGColor;
  41. self.sampleView.layer.borderWidth = 1.0;
  42. self.sampleView.fillColor = [UIColor yellowColor];
  43. self.sampleView.opcity = 1.0;
  44. self.sampleView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
  45. [self.view addSubview:self.sampleView];
  46. self.colorView = [[CPDFColorSelectView alloc] initWithFrame:CGRectMake(0, 190, self.view.frame.size.width, 90)];
  47. self.colorView.delegate = self;
  48. self.colorView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  49. [self.view addSubview:self.colorView];
  50. self.opacitySliderView = [[CPDFOpacitySliderView alloc] init];
  51. self.opacitySliderView.delegate = self;
  52. self.opacitySliderView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  53. [self.view addSubview:self.opacitySliderView];
  54. self.view.backgroundColor = [UIColor whiteColor];
  55. [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
  56. [self commomInitTitle];
  57. }
  58. - (void)viewWillLayoutSubviews {
  59. [super viewWillLayoutSubviews];
  60. self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 5, 120, 50);
  61. self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, 50);
  62. self.sampleView.frame = CGRectMake((self.view.frame.size.width - 300)/2, 60, 300, 120);
  63. self.opacitySliderView.frame = CGRectMake(10, 280, self.view.frame.size.width - 20, 90);
  64. self.colorPicker.frame = self.view.frame;
  65. }
  66. - (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  67. [super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
  68. [self updatePreferredContentSizeWithTraitCollection:newCollection];
  69. }
  70. #pragma mark - Protect Methods
  71. - (void)commomInitTitle {
  72. self.titleLabel.text = NSLocalizedString(@"Note", nil);
  73. self.sampleView.selecIndex = CPDFSamplesHighlight;
  74. self.colorView.colorLabel.text = NSLocalizedString(@"Color:", nil);
  75. }
  76. - (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
  77. self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 270 : 420);
  78. }
  79. #pragma mark - Action
  80. - (void)buttonItemClicked_back:(id)sender {
  81. [self dismissViewControllerAnimated:YES completion:nil];
  82. }
  83. #pragma mark - CPDFColorSelectViewDelegate
  84. - (void)selectColorView:(CPDFColorSelectView *)select {
  85. _colorPicker = [[CPDFColorPickerView alloc] initWithFrame:self.view.frame];
  86. _colorPicker.delegate = self;
  87. _colorView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  88. _colorPicker.backgroundColor = [UIColor whiteColor];
  89. [self.view addSubview:self.colorPicker];
  90. }
  91. - (void)selectColorView:(CPDFColorSelectView *)select color:(UIColor *)color {
  92. self.sampleView.fillColor = color;
  93. [self.sampleView setNeedsDisplay];
  94. }
  95. #pragma mark - CPDFColorPickerViewDelegate
  96. - (void)pickerView:(CPDFColorPickerView *)colorPickerView color:(UIColor *)color {
  97. self.sampleView.fillColor = color;
  98. [self.sampleView setNeedsDisplay];
  99. }
  100. #pragma mark - CPDFOpacitySliderViewDelegate
  101. - (void)opacitySliderView:(CPDFOpacitySliderView *)opacitySliderView opacity:(CGFloat)opacity {
  102. self.sampleView.opcity = opacity;
  103. [self.sampleView setNeedsDisplay];
  104. }
  105. @end