使用CALayer变换进行变换后,对UIView的边缘进行抗锯齿处理 [英] Antialiasing edges of UIView after transformation using CALayer's transform

查看:523
本文介绍了使用CALayer变换进行变换后,对UIView的边缘进行抗锯齿处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIView 对象,它使用 CALayer 的转换进行旋转:

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的边缘进行抗锯齿处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆