Browse Source

PDFAnnotation(iOS) - 注释模块UI处理

dinglingui 1 year ago
parent
commit
559f728659

+ 5 - 1
Annotation-Ctrl-Demo/Annotation-Ctrl-Demo/CPDFViewController.m

@@ -147,7 +147,11 @@
         height += self.view.safeAreaInsets.bottom;
 
     if(CToolModelAnnotation == self.pdfListView.toolModel) {
-        self.annotationBar.frame = CGRectMake(0, self.view.frame.size.height - height, self.view.frame.size.width, height);
+        if (@available(iOS 11.0, *)) {
+            self.annotationBar.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.frame.size.height - height, self.view.frame.size.width- self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, height);
+        } else {
+            self.annotationBar.frame = CGRectMake(0, self.view.frame.size.height - height, self.view.frame.size.width, height);
+        }
     } else {
         self.annotationBar.frame = CGRectMake(0, self.view.bounds.size.height, self.view.frame.size.width, height);
     }

+ 56 - 20
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFShape/CPDFShapeArrowViewController.m

@@ -14,6 +14,7 @@
 #import "CPDFShareCircleViewController_Header.h"
 #import "CPDFArrowStyleView.h"
 #import "CShapeSelectView.h"
+#import "CPDFDrawArrowView.h"
 
 #import <compdfkit_tools/CPDFColorUtils.h>
 
@@ -54,6 +55,10 @@
     self.arrowLabel.font = [UIFont systemFontOfSize:12.0];
     [self.scrcollView addSubview:self.arrowLabel];
     
+    
+    CPDFDrawArrowView *arrView = [[CPDFDrawArrowView alloc] initWithFrame:CGRectMake(0, 0, 80, 30)];
+
+    
     self.arrowBtn = [[UIButton alloc] init];
     [self.arrowBtn setImage:[UIImage imageNamed:@"CPDFShapeArrowImageStart" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
     self.arrowBtn.layer.borderWidth = 1.0;
@@ -77,6 +82,8 @@
     self.trialBtn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
     [self.scrcollView addSubview:self.trialBtn];
     
+    self.fillColorSelectView.hidden = YES;
+    
     self.view.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
 }
 
@@ -86,25 +93,43 @@
     self.scrcollView.contentSize = CGSizeMake(self.view.frame.size.width, 500);
     
     if (@available(iOS 11.0, *)) {
-        self.opacitySliderView.frame = CGRectMake(self.view.safeAreaInsets.left, 180, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 90);
-        self.thicknessView.frame = CGRectMake(self.view.safeAreaInsets.left, 270, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 90);
+        CGFloat offsetY = 0;
         self.colorView.frame = CGRectMake(self.view.safeAreaInsets.left, 0,self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 90);
-        self.fillColorSelectView.frame = CGRectMake(self.view.safeAreaInsets.left, 90,self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 90);
-        self.dottedView.frame = CGRectMake(self.view.safeAreaInsets.left, 360, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 90);
-        self.arrowLabel.frame = CGRectMake(self.view.safeAreaInsets.left+20, 450, 100, 45);
-        self.arrowBtn.frame = CGRectMake(self.view.frame.size.width - 100 - self.view.safeAreaInsets.right, 457.5, 80, 30);
-        self.trialLabel.frame = CGRectMake(self.view.safeAreaInsets.left+20, 495, 100, 45);
-        self.trialBtn.frame = CGRectMake(self.view.frame.size.width - 100- self.view.safeAreaInsets.right, 502.5, 80, 30);
+        offsetY+= self.colorView.frame.size.height;
+        self.opacitySliderView.frame = CGRectMake(self.view.safeAreaInsets.left, offsetY, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 90);
+        offsetY+= self.opacitySliderView.frame.size.height;
+
+        self.thicknessView.frame = CGRectMake(self.view.safeAreaInsets.left, offsetY, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 90);
+        offsetY+= self.thicknessView.frame.size.height;
+
+        self.dottedView.frame = CGRectMake(self.view.safeAreaInsets.left, offsetY, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 90);
+        offsetY+= self.dottedView.frame.size.height;
+
+        self.arrowLabel.frame = CGRectMake(self.view.safeAreaInsets.left+20, offsetY, 100, 45);
+        self.arrowBtn.frame = CGRectMake(self.view.frame.size.width - 100 - self.view.safeAreaInsets.right, offsetY + 7.5, 80, 30);
+        offsetY+= self.arrowLabel.frame.size.height;
+        
+        self.trialLabel.frame = CGRectMake(self.view.safeAreaInsets.left+20, offsetY, 100, 45);
+        self.trialBtn.frame = CGRectMake(self.view.frame.size.width - 100- self.view.safeAreaInsets.right, offsetY + 7.5, 80, 30);
     } else {
-        self.opacitySliderView.frame = CGRectMake(10, 180, self.view.frame.size.width - 20, 90);
-        self.thicknessView.frame = CGRectMake(10, 270, self.view.frame.size.width - 20, 90);
-        self.dottedView.frame = CGRectMake(10, 360, self.view.frame.size.width - 20, 90);
-        self.fillColorSelectView.frame = CGRectMake(10, 210,self.view.frame.size.width - 20, 90);
-        self.colorView.frame = CGRectMake(10, 0,self.view.frame.size.width, 90);
-        self.arrowLabel.frame = CGRectMake(15, 450, 60, 45);
-        self.arrowBtn.frame = CGRectMake(self.view.frame.size.width - 75, 457.5, 60, 45);
-        self.trialLabel.frame = CGRectMake(15, 495, 60, 45);
-        self.trialBtn.frame = CGRectMake(self.view.frame.size.width - 75, 502.5, 60, 45);
+        CGFloat offsetY = 0;
+        self.colorView.frame = CGRectMake(0, 0,self.view.frame.size.width, 90);
+        offsetY+= self.colorView.frame.size.height;
+        self.opacitySliderView.frame = CGRectMake(0, offsetY, self.view.frame.size.width - 0, 90);
+        offsetY+= self.opacitySliderView.frame.size.height;
+
+        self.thicknessView.frame = CGRectMake(0, offsetY, self.view.frame.size.width, 90);
+        offsetY+= self.thicknessView.frame.size.height;
+
+        self.dottedView.frame = CGRectMake(0, offsetY, self.view.frame.size.width, 90);
+        offsetY+= self.dottedView.frame.size.height;
+
+        self.arrowLabel.frame = CGRectMake(20, offsetY, 100, 45);
+        self.arrowBtn.frame = CGRectMake(self.view.frame.size.width - 100, offsetY + 7.5, 80, 30);
+        offsetY+= self.arrowLabel.frame.size.height;
+        
+        self.trialLabel.frame = CGRectMake(20, offsetY, 100, 45);
+        self.trialBtn.frame = CGRectMake(self.view.frame.size.width - 100, offsetY + 7.5, 80, 30);
     }
 }
 
@@ -129,25 +154,32 @@
 }
 
 - (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
-    self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 350 : 750);
+    if([self.startArrowStyleView superview] || [self.endArrowStyleView superview]) {
+        self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, 120);
+    } else {
+        self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 350 : 660);
+
+    }
 }
 
 #pragma mark - Action
 
 - (void)buttonItemClicked_start:(id)sender {
-    self.startArrowStyleView = [[CPDFArrowStyleView alloc] initWirhTitle:@"Arrow Style"];
+    self.startArrowStyleView = [[CPDFArrowStyleView alloc] initWirhTitle:NSLocalizedString(@"Arrow Style",nil)];
     self.startArrowStyleView.frame = self.view.frame;
     self.startArrowStyleView.delegate = self;
     self.startArrowStyleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
     [self.view addSubview:self.startArrowStyleView];
+    [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
 }
 
 - (void)buttonItemClicked_trial:(id)sender {
-    self.endArrowStyleView = [[CPDFArrowStyleView alloc] initWirhTitle:@"Arrowtail style"];
+    self.endArrowStyleView = [[CPDFArrowStyleView alloc] initWirhTitle:NSLocalizedString(@"Arrowtail style",nil)];
     self.endArrowStyleView.frame = self.view.frame;
     self.endArrowStyleView.delegate = self;
     self.endArrowStyleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
     [self.view addSubview:self.endArrowStyleView];
+    [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
 }
 
 #pragma mark - CPDFArrowStyleViewDelegate
@@ -170,6 +202,10 @@
     }
 }
 
+- (void)arrowStyleRemoveView:(CPDFArrowStyleView *)arrowStyleView {
+    [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
+}
+
 #pragma mark - CPDFOpacitySliderViewDelegate
 
 - (void)opacitySliderView:(CPDFOpacitySliderView *)opacitySliderView opacity:(CGFloat)opacity {

+ 1 - 1
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBar.h

@@ -70,7 +70,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (void)buttonItemClicked_open:(UIButton *)button;
 
-- (void)openSignatureAnnotation:(CPDFSignatureAnnotation *)signatureAnnotation;
+- (void)openSignatureAnnotation:(CPDFSignatureWidgetAnnotation *)signatureAnnotation;
 
 - (void)addStampAnnotationWithPage:(CPDFPage *)page point:(CGPoint)point;
 

+ 14 - 13
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBar.m

@@ -101,6 +101,12 @@
 - (void)layoutSubviews {
     [super layoutSubviews];
     self.scrollView.frame = CGRectMake(0, 0, self.frame.size.width-self.propertiesBar.frame.size.width, self.frame.size.height);
+    
+    if (@available(iOS 11.0, *)) {
+        self.topToolBar.frame = CGRectMake(self.pdfListView.frame.size.width-30-self.topToolBar.frame.size.width, self.window.safeAreaInsets.top, self.topToolBar.frame.size.width, 50);
+    } else {
+        self.topToolBar.frame = CGRectMake(self.pdfListView.frame.size.width-30-self.topToolBar.frame.size.width, 64, self.topToolBar.frame.size.width, 50);
+    }
 }
 
 #pragma mark - Public Methods
@@ -131,7 +137,7 @@
     }
 }
 
-- (void)openSignatureAnnotation:(CPDFSignatureAnnotation *)signatureAnnotation {
+- (void)openSignatureAnnotation:(CPDFSignatureWidgetAnnotation *)signatureAnnotation {
     self.signatureAnnotation = signatureAnnotation;
     CAnnotStyle *annotStytle = self.annotManage.annotStyle;
     AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
@@ -248,19 +254,16 @@
     }
     self.annotationBtns = annotationBtns;
     
-    if (UIUserInterfaceIdiomPhone == UI_USER_INTERFACE_IDIOM()) {
-        _scrollView.contentSize = CGSizeMake(offsetX, _scrollView.bounds.size.height);
-    } else {
-        _scrollView.contentSize = CGSizeMake(_scrollView.bounds.size.width, offsetX);
-    }
+    _scrollView.contentSize = CGSizeMake(offsetX, _scrollView.bounds.size.height);
     [self.scrollView bringSubviewToFront:self.propertiesBar];
     
-    _propertiesBar = [[UIView alloc] initWithFrame:CGRectMake(self.bounds.size.width - 150, 0, 140, 44)];
+    CGFloat offset = 10;
+
+    CGFloat prWidth = buttonSize * 3 + offset;
+    _propertiesBar = [[UIView alloc] initWithFrame:CGRectMake(self.bounds.size.width - prWidth, 0, prWidth, 44)];
     _propertiesBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
     [self addSubview:self.propertiesBar];
     
-    CGFloat offset = 10;
-
     UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(offset, 12, 1, 20)];
     if (@available(iOS 13.0, *))
         lineView.backgroundColor = [UIColor labelColor];
@@ -481,15 +484,13 @@
 
         self.propertiesBtn.enabled = NO;
         if (@available(iOS 11.0, *)) {
-            self.topToolBar = [[CPDFInkTopToolBar alloc] initWithFrame:CGRectMake(50, self.window.safeAreaInsets.top, self.pdfListView.frame.size.width-100, 50)];
+            self.topToolBar = [[CPDFInkTopToolBar alloc] initWithFrame:CGRectMake(self.pdfListView.frame.size.width-30- 300, self.window.safeAreaInsets.top, 300, 50)];
             self.topToolBar.delegate = self;
             
-            self.topToolBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
             [self.pdfListView addSubview:self.topToolBar];
         } else {
-            self.topToolBar = [[CPDFInkTopToolBar alloc] initWithFrame:CGRectMake(50, 64, self.pdfListView.frame.size.width-100, 50)];
+            self.topToolBar = [[CPDFInkTopToolBar alloc] initWithFrame:CGRectMake(self.pdfListView.frame.size.width-30-300, 64, 300, 50)];
             self.topToolBar.delegate = self;
-            self.topToolBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
             [self.pdfListView addSubview:self.topToolBar];
         }
     } else if (CPDFViewAnnotationModeSignature == self.selectedIndex) {

+ 5 - 3
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFArrowStyleCell.m

@@ -12,6 +12,7 @@
 
 #import "CPDFArrowStyleCell.h"
 #import "CPDFDrawArrowView.h"
+#import "CPDFColorUtils.h"
 
 @implementation CPDFArrowStyleCell
 
@@ -19,9 +20,10 @@
 
 - (instancetype)initWithFrame:(CGRect)frame {
     if (self = [super initWithFrame:frame]) {
-        self.contextView = [[CPDFDrawArrowView alloc] initWithFrame:self.contentView.bounds];
-        self.contextView.backgroundColor = [UIColor whiteColor];
-        [self.contentView addSubview:self.contextView];
+        self.contextView = [[CPDFDrawArrowView alloc] initWithFrame:CGRectMake(1, 1, self.bounds.size.width - 2, self.bounds.size.height - 2)];
+        self.contextView.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
+        self.contentView.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
+        [self addSubview:self.contextView];
     }
     return self;
 }

+ 2 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFArrowStyleView.h

@@ -22,6 +22,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (void)arrowStyleView:(CPDFArrowStyleView *)arrowStyleView selectIndex:(NSInteger)selectIndex;
 
+- (void)arrowStyleRemoveView:(CPDFArrowStyleView *)arrowStyleView;
+
 @end
 
 @interface CPDFArrowStyleView : UIView

+ 10 - 2
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFArrowStyleView.m

@@ -46,11 +46,11 @@
         [self.headerView addSubview:self.backBtn];
         
         self.titleLabel = [[UILabel alloc] init];
-        self.titleLabel.text = NSLocalizedString(title, nil);
+        self.titleLabel.text = title;
         [self.headerView addSubview:self.titleLabel];
         
         UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
-        layout.itemSize = CGSizeMake(110, 50);
+        layout.itemSize = CGSizeMake((self.frame.size.width - 5.0* 7)/6, 30);
         layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
         layout.minimumInteritemSpacing = 5;
         layout.minimumLineSpacing = 5;
@@ -78,10 +78,17 @@
 
 - (void)buttonItemClicked_back:(id)sender {
     [self removeFromSuperview];
+    if (self.delegate && [self.delegate respondsToSelector:@selector(arrowStyleRemoveView:)]) {
+        [self.delegate arrowStyleRemoveView:self];
+    }
 }
 
 #pragma mark - UICollectionViewDataSource
 
+- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
+    return CGSizeMake((self.frame.size.width - 5.0* 7)/6, 30);
+}
+
 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
     return 6;
 }
@@ -90,6 +97,7 @@
     CPDFArrowStyleCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
     cell.contextView.selectIndex = indexPath.item;
     [cell.contentView setNeedsDisplay];
+    cell.backgroundColor = [UIColor clearColor];
     return cell;
 }
 

+ 2 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFDrawArrowView.h

@@ -27,6 +27,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 @property (nonatomic, assign) NSInteger selectIndex;
 
+- (UIImage *)shotShareImage;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 27 - 18
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFDrawArrowView.m

@@ -21,8 +21,8 @@
 - (void)drawRect:(CGRect)rect {
     [super drawRect:rect];
     CGContextRef context = UIGraphicsGetCurrentContext();
-    CGPoint start = CGPointMake(CGRectGetMinX(rect)+20, CGRectGetMidY(rect));
-    CGPoint end = CGPointMake(CGRectGetMaxX(rect)-20, CGRectGetMidY(rect));
+    CGPoint start = CGPointMake(CGRectGetMinX(rect)+10, CGRectGetMidY(rect));
+    CGPoint end = CGPointMake(CGRectGetMaxX(rect)-10, CGRectGetMidY(rect));
     [self drawArrow:context startPoint:start endPoint:end];
 }
 
@@ -52,13 +52,13 @@
             break;
         case CPDFDrawTriangle:
         {
-            CGContextMoveToPoint(context, start.x, start.y);
-            CGContextAddLineToPoint(context, end.x, end.y);
+            CGContextMoveToPoint(context, start.x-5, start.y);
+            CGContextAddLineToPoint(context, end.x-5, end.y);
             CGContextStrokePath(context);
             
-            CGContextMoveToPoint(context, end.x, end.y-5);
-            CGContextAddLineToPoint(context, end.x+5, end.y);
-            CGContextAddLineToPoint(context, end.x, end.y+5);
+            CGContextMoveToPoint(context, end.x-5, end.y-5);
+            CGContextAddLineToPoint(context, end.x, end.y);
+            CGContextAddLineToPoint(context, end.x-5, end.y+5);
             CGContextClosePath(context);
             CGContextStrokePath(context);
         }
@@ -66,13 +66,13 @@
         case CPDFDrawSquare:
         {
             CGContextMoveToPoint(context, start.x, start.y);
-            CGContextAddLineToPoint(context, end.x, end.y);
+            CGContextAddLineToPoint(context, end.x-10, end.y);
             CGContextStrokePath(context);
             
-            CGContextMoveToPoint(context, end.x, end.y-5);
+            CGContextMoveToPoint(context, end.x-10, end.y-5);
+            CGContextAddLineToPoint(context, end.x-10, end.y+5);
             CGContextAddLineToPoint(context, end.x, end.y+5);
-            CGContextAddLineToPoint(context, end.x+10, end.y+5);
-            CGContextAddLineToPoint(context, end.x+10, end.y-5);
+            CGContextAddLineToPoint(context, end.x, end.y-5);
             CGContextClosePath(context);
             CGContextStrokePath(context);
         }
@@ -80,23 +80,23 @@
         case CPDFDrawCircle:
         {
             CGContextMoveToPoint(context, start.x, start.y);
-            CGContextAddLineToPoint(context, end.x, end.y);
+            CGContextAddLineToPoint(context, end.x-10, end.y);
             CGContextStrokePath(context);
             
-            CGContextAddArc(context, end.x+2.7, end.y, 5, 0, 2*3.14159265358979323846, 0);
+            CGContextAddArc(context, end.x-7, end.y, 5, 0, 2*M_PI, 0);
             CGContextDrawPath(context, kCGPathStroke);
         }
             break;
         case CPDFDrawDiamond:
         {
             CGContextMoveToPoint(context, start.x, start.y);
-            CGContextAddLineToPoint(context, end.x, end.y);
+            CGContextAddLineToPoint(context, end.x-10, end.y);
             CGContextStrokePath(context);
             
-            CGContextMoveToPoint(context, end.x, end.y);
-            CGContextAddLineToPoint(context, end.x+5, end.y+5);
-            CGContextAddLineToPoint(context, end.x+10, end.y);
-            CGContextAddLineToPoint(context, end.x+5, end.y-5);
+            CGContextMoveToPoint(context, end.x-10, end.y);
+            CGContextAddLineToPoint(context, end.x-5, end.y+5);
+            CGContextAddLineToPoint(context, end.x, end.y);
+            CGContextAddLineToPoint(context, end.x-5, end.y-5);
             CGContextClosePath(context);
             CGContextStrokePath(context);
         }
@@ -106,4 +106,13 @@
     }
 }
 
+- (UIImage *)shotShareImage {
+    UIGraphicsBeginImageContext(CGSizeMake(self.layer.bounds.size.width, self.layer.bounds.size.height));
+    CGContextRef context = UIGraphicsGetCurrentContext();
+    [self.layer renderInContext:context];
+    UIImage* tImage = UIGraphicsGetImageFromCurrentImageContext();
+    UIGraphicsEndImageContext();
+    return tImage;
+}
+
 @end