【问题标题】:Rotation of image not smooth [duplicate]图像的旋转不平滑[重复]
【发布时间】:2012-11-02 14:17:36
【问题描述】:

可能重复:
Any quick and dirty anti-aliasing techniques for a rotated UIImageView?

我的应用中有一个带有边框的图像视图 (myImage):

[myImage.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[myImage.layer setBorderWidth: 1];

然后我使用以下代码将其旋转,在本例中旋转 20 度。

NSInteger r = 20;
CABasicAnimation *imageRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
imageRotation.toValue = [NSNumber numberWithFloat:((r*M_PI)/ -180)];
imageRotation.duration = 0.01;
imageRotation.repeatCount = 1;
imageRotation.removedOnCompletion = NO;
imageRotation.autoreverses=NO;
imageRotation.fillMode = kCAFillModeForwards;
[myImage.layer addAnimation:imageRotation forKey:@"imageRotation"];

上面的代码旋转了图像,但是你看不到它的动画(因为 imageRotation.duration 非常低)。旋转完成后,结果是一个图像视图,即移动或旋转,但已经旋转了 20。

此代码运行良好,但是边框和包含图像的线条不流畅,这破坏了我的应用程序的显示。

有谁知道这可能是什么原因造成的,或者如何解决。干杯

【问题讨论】:

  • 什么不流畅?图片(视图)和边框,还是图片视图和边框的动画?
  • 哦,我的解释很糟糕。查看更新的问题。
  • 在动画中使用duration属性,然后也使用CAMeidaTimingFunction使其更加明显。

标签: iphone objective-c ios cocoa-touch


【解决方案1】:

试试

CGContextSetInterpolationQuality(context, kCGInterpolationHigh);

【讨论】:

    【解决方案2】:

    您是否尝试过在 imageView 中使用 transform 属性?试试这个:

    myImage.transform = CGAffineTransformMakeRotation((r*M_PI)/ -180);
    

    【讨论】:

    • 嗯,不用说,这将 8 行更改为 1 行,因此比我使用的代码更好。但是,边框和图像的边缘仍然是锯齿状的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    相关资源
    最近更新 更多