简体   繁体   English

如何在旋转的UIView上进行抗锯齿(不是UIImageView)

[英]How to do antialiasing on a rotated UIView (NOT UIImageView)

My issue is basically the the same as this one . 我的问题基本上与此与相同。 I have a UIView and when I rotate it usding CGAffineTransformMakeRotation, the edges are not being antialiased. 我有一个UIView,当我旋转它使用CGAffineTransformMakeRotation时,其边缘没有被消除锯齿。

I tried both adding the view as a subview in a bigger UIView and using a transparent border on the view but none of these worked. 我尝试将视图添加为更大的UIView中的子视图,并在视图上使用透明边框,但是这些都不起作用。

The OP of the aforementioned post solved this by making an image with transparent borders in photoshop and using a UIImageView instead but I cannot do the same because the size of the UIView is determined on runtime. 上述文章的OP通过在Photoshop中制作具有透明边框的图像并改为使用UIImageView来解决了此问题,但是由于UIView的大小是在运行时确定的,因此我无法做到这一点。

Does anyone know any solutions to this problem? 有谁知道这个问题的解决方案吗?

Note that this is not a duplicate of this post because I am interested in using a UIView and NOT a UIImageView. 请注意,这不是重复这个职位,因为我有兴趣使用一个UIView和NOT一个UIImageView。

尝试在App-info.plist中设置UIViewEdgeAntialiasing = YES

I solved this by creating a 3x3 px image in photoshop. 我通过在Photoshop中创建3x3 px图像解决了此问题。 The center pixel of the image has the color I wanted my background to have and the rest of the pixels are transparent. 图像的中心像素具有我希望背景具有的颜色,其余像素是透明的。 Then I was able to use an instance of UIImageView and to define the frame size at runtime by using the -stretchableImageWithLeftCapWidth:topCapHeight: method. 然后,我可以使用UIImageView的实例,并通过-stretchableImageWithLeftCapWidth:topCapHeight:方法在运行时定义帧大小。

This solution, of course still does not work for UIViews but that way you can circumvent the "variable size" issue and use a UIImageView instead. 当然,该解决方案仍然不适用于UIView,但是通过这种方式,您可以规避“可变大小”问题,而改用UIImageView。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM