【问题标题】:iOS8 lines drawn with coreGraphics fade over time in UIImageView使用 coreGraphics 绘制的 iOS8 线条在 UIImageView 中随着时间的推移而褪色
【发布时间】:2014-10-06 15:22:01
【问题描述】:

我有一个非常奇怪的问题。在 iOS8 中,仅在 ipad 2 上(适用于所有设备上的 iOS7 和 iOS8 中的 mini),我拥有的签名面板将导致线条/绘制的对象随着用户将手指放在 UIImageView 上的时间越长而消失。

谷歌搜索一无所获,有什么想法吗?这是绘制用户水龙头的代码。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
swiped = YES;

UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
currentPoint.y -= 20;

UIGraphicsBeginImageContext(self.view.frame.size);
[_drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
_drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

lastPoint = currentPoint;

}

【问题讨论】:

  • 你试过使用 CGContextRef context = UIGraphicsGetCurrentContext();作为变量..并使用上下文代替 UIGraphicsGetCurrentContext().. ?
  • 有趣...是的,让我试试
  • 我尝试在 iOS8 中测试您的代码,它工作正常:/ .
  • 您使用的是 iPad 2 吗?模拟器 ipad 2 和 ipad mini 设备都可以正常工作。但 ipad 2 设备本身会导致问题。
  • 是的,我确实尝试过使用 Xcode Version 6.0.1 (6A317)iPad 2 with iOS 8.0.2 。你试过用UIBezierPath代替吗?

标签: ios objective-c uiimageview core-graphics


【解决方案1】:

我也遇到了同样的问题,刚刚发现原因。

我的 UIImageView 在 UITableViewCell 中,并且 UIImageView 的自动调整大小掩码设置为 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth.

事实证明,删除 UIViewAutoresizingFlexibleHeight 并为 UIImageView 设置显式高度,解决了问题。

我怀疑这是由于 iOS8 中表格单元格的不同行为,因为我知道现在有一个自动调整大小功能(我还没有使用过,因为我有自己的实现)。我怀疑这对灵活的高度调整蒙版造成了严重破坏,导致失真。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多