2

What I am doing is, I've an imageview that displays an image and above it I've a overlay view where I draw the annotations. It's working fine on other devices but in iPhone 12 overlays is not displayed!Tried using CATiledLayer with no luck! I am just giving the screenshot of iPhone SE & iPhone 12.

This is iPhone SE output

enter image description here

And this is iPhone 12 output:

enter image description here

I am using UIBezierPath to draw the lines! This is how I am drawing the lines:

+(UIBezierPath*) pathForArrowUsingStartPoint:(CGPoint) startPoint endPoint:(CGPoint) endPoint superRect:(CGRect) superRect lineWidth:(double) LINE_WIDTH
                                   arrowSize:(double) ARROW_SIZE arrowTipSize:(double) ARROW_TIP_DIST
{
    UIBezierPath* bp = [UIBezierPath bezierPath];
    CGPoint transLatedEndPoint = [Annotation convertBetweenUIViewCoordAndXYCoord:endPoint inRect:superRect];
    CGPoint transLatedStartPoint = [Annotation convertBetweenUIViewCoordAndXYCoord:startPoint inRect:superRect];
    CGFloat lineAngle = [Annotation angleBetweenPoint1:transLatedStartPoint Point2:transLatedEndPoint];
    
    //calculate the rect to draw
    
    CGPoint p0 ;
    p0.x = transLatedEndPoint.x + LINE_WIDTH * cosf(lineAngle + M_PI/2);
    p0.y = transLatedEndPoint.y + LINE_WIDTH * sinf(lineAngle + M_PI/2);
    
    p0 = [Annotation convertBetweenUIViewCoordAndXYCoord:p0 inRect:superRect];
    
    CGPoint p1;
    p1.x = transLatedEndPoint.x + LINE_WIDTH * cosf(lineAngle - M_PI/2);
    p1.y = transLatedEndPoint.y + LINE_WIDTH * sinf(lineAngle - M_PI/2);
    
    p1 = [Annotation convertBetweenUIViewCoordAndXYCoord:p1 inRect:superRect];
    
    CGPoint p2 ;
    p2.x = transLatedStartPoint.x - LINE_WIDTH * cosf(lineAngle + M_PI/2);
    p2.y = transLatedStartPoint.y - LINE_WIDTH * sinf(lineAngle + M_PI/2);
    
    p2 = [Annotation convertBetweenUIViewCoordAndXYCoord:p2 inRect:superRect];
    
    CGPoint p3;
    p3.x = transLatedStartPoint.x - LINE_WIDTH * cosf(lineAngle - M_PI/2);
    p3.y = transLatedStartPoint.y - LINE_WIDTH * sinf(lineAngle - M_PI/2);
    
    p3 = [Annotation convertBetweenUIViewCoordAndXYCoord:p3 inRect:superRect];
    
    // now drawing arrow head using triangle
    
    CGPoint arrow0P0;
    arrow0P0.x = transLatedEndPoint.x - ARROW_SIZE * cosf(lineAngle - M_PI/4);
    arrow0P0.y = transLatedEndPoint.y - ARROW_SIZE * sinf(lineAngle - M_PI/4);
    
    arrow0P0 = [Annotation convertBetweenUIViewCoordAndXYCoord:arrow0P0 inRect:superRect];
    
    CGPoint arrow0P1;
    arrow0P1.x = transLatedEndPoint.x - ARROW_SIZE * cosf(lineAngle + M_PI/4);
    arrow0P1.y = transLatedEndPoint.y - ARROW_SIZE * sinf(lineAngle + M_PI/4);
    
    arrow0P1 = [Annotation convertBetweenUIViewCoordAndXYCoord:arrow0P1 inRect:superRect];
    
    CGPoint arrow0Tip;
    arrow0Tip.x = transLatedEndPoint.x + ARROW_TIP_DIST * cosf(lineAngle);
    arrow0Tip.y = transLatedEndPoint.y + ARROW_TIP_DIST * sinf(lineAngle);
    arrow0Tip = [Annotation convertBetweenUIViewCoordAndXYCoord:arrow0Tip inRect:superRect];
    
    [bp moveToPoint:p0];
    [bp addLineToPoint:p1];
    [bp addLineToPoint:p2];
    [bp addLineToPoint:p3];
    [bp closePath];
    //arrows
    
    [bp moveToPoint:arrow0P0];
    [bp addLineToPoint:arrow0Tip];
    [bp addLineToPoint:arrow0P1];
    [bp addLineToPoint:arrow0P0];
    
    [bp closePath];
    return bp;
    
}
Rashad
  • 11,057
  • 4
  • 45
  • 73
  • Especially when you zoom, you need to be careful. At some stage the size is ignored and marked as bogus. I've forced zoom to be between 0.2 and 2 to prevent running into the error you get. I suspect the scale of 3 here is the problem. – skaak Nov 30 '20 at 14:58
  • @skaak > I've not set zoom scale to that point. Maximum zoon scale is 2! How it is getting that in iPhone 12 not sure! – Rashad Nov 30 '20 at 16:49

2 Answers2

1

Just a comment really, put here for the ease of formatting. You should have some kind of a zoom scale somewhere, say a property

@property (nonatomic) CGFloat zoom;

and then set it when the scrollview zoom, something like

- (void) scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
    [self setZoom:scale * self.zoom inScrollView:scrollView];
}

and then in setZoom apply your limits. YMMV. Just what worked for me when getting similar problem.

skaak
  • 2,988
  • 1
  • 8
  • 16
1

Newer device has scale factor of 3. For large image a canvas that big was throwing the error and my canvas was not visible. Just changing the scale factor of my drawing canvas does the trick.

self.drawingCanvas.contentScaleFactor = 2.0;
Rashad
  • 11,057
  • 4
  • 45
  • 73