问题描述
我有一个使用 CALayer
的变换旋转的 UIView
对象:
I have a UIView
object that rotates using CALayer
's transform:
// Create uiview object.
UIImageView *block = [[UIImageView alloc] initWithFrame....]
// Apply rotation.
CATransform3D basicTrans = CATransform3DIdentity;
basicTrans.m34 = 1.0/-distance;
blockImage.layer.transform = CATransform3DRotate(basicTrans, rangle, 1.0f, 0.0f, 0.0f);
旋转对象的边缘后没有抗锯齿.我需要对它们进行抗锯齿.请帮帮我.怎么办?
After rotating the edges of the object are not antialiasing. I need to antialias them.Help me, please. How can it be done?
推荐答案
一种方法是将图像放置在另一个大 5 像素的视图中.更大的视图应该有一个透明的光栅化边框,可以平滑 UIImageView 的边缘:
One way to do this is by placing the image inside another view that's 5 pixels bigger. The bigger view should have a transparent rasterized border that will smooth the edges of the UIImageView:
view.layer.borderWidth = 3;
view.layer.borderColor = [UIColor clearColor].CGColor;
view.layer.shouldRasterize = YES;
view.layer.rasterizationScale = [[UIScreen mainScreen] scale];
然后,将您的 UIImageView 放置在该父视图中并将其居中(每条边缘周围 2.5 像素).
Then, place your UIImageView inside this parent view and center it (With 2.5 pixels around each edge).
最后,旋转父视图而不是图像视图.
Finally, rotate the parent view instead of the image view.
效果很好 - 您还可以将整个内容封装在创建层次结构的类中.
It works very well - you can also encapsulate the whole thing in class that creates the hierarchy.
这篇关于使用 CALayer 的变换进行变换后 UIView 的抗锯齿边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!