【问题标题】:[CALayer display]: Ignoring bogus layer size (8681.000000, 3508.000000), contentsScale 3.000000, backing store size (26043.000000, 10524.000000)[CALayer display]:忽略虚假层大小(8681.000000、3508.000000)、contentsScale 3.000000、后备存储大小(26043.000000、10524.000000)
【发布时间】:2020-11-30 10:15:49
【问题描述】:

我正在做的是,我有一个显示图像的图像视图,在它上面我有一个覆盖视图,我在其中绘制注释。它在其他设备上运行良好,但在 iPhone 12 中不显示叠加层!尝试使用 CATiledLayer,但没有成功!我只是提供 iPhone SE 和 iPhone 12 的屏幕截图。

这是 iPhone SE 输出

这是 iPhone 12 的输出:

我正在使用 UIBezierPath 来绘制线条!这就是我画线的方式:

+(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;
    
}

【问题讨论】:

  • 尤其是缩放时,需要小心。在某些阶段,大小会被忽略并标记为伪造的。我已经强制缩放在 0.2 和 2 之间,以防止遇到你得到的错误。我怀疑这里的 3 比例是问题所在。
  • @skaak > 我还没有设置缩放比例。最大缩放比例为 2!不确定如何在 iPhone 12 中实现这一点!

标签: ios objective-c core-graphics uibezierpath iphone12


【解决方案1】:

真的只是一个评论,放在这里是为了便于格式化。你应该在某处有某种缩放比例,比如一个属性

@property (nonatomic) CGFloat zoom;

然后在滚动视图缩放时设置它,类似于

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

然后在setZoom 应用您的限制。 YMMV。遇到类似问题时,这对我有用。

【讨论】:

    【解决方案2】:

    较新的设备的比例因子为 3。对于大图像,那么大的画布会引发错误,并且我的画布不可见。只需更改我的绘图画布的比例因子就可以了。

    self.drawingCanvas.contentScaleFactor = 2.0;
    

    【讨论】:

    • 将图层的 contentsScale 设置为 1 为我解决了这个问题,设置视图的 contentScaleFactor 并没有解决它
    • 但是颗粒感很足
    • 我可以将 contentsScale 设置为 1.7 而不会出现此错误,而且在颗粒度方面也不算太糟糕
    猜你喜欢
    • 1970-01-01
    • 2011-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    • 2014-02-08
    • 2021-05-18
    相关资源
    最近更新 更多