使用 CATransform3DRotate 时的抗锯齿线
我将代码从答案复制到 如何申请透视变换为 UIView? 以实现下图。但请注意,分隔级别的锯齿线。是否有办法以消除这些锯齿线锯齿的方式执行这种透视变换?
编辑 我已经尝试过 DarkDust 在这篇文章的评论中提供的解决方案。似乎没有一个起作用。这是我的代码:
levelView = [[UIControl alloc] initWithFrame:CGRectMake(100, 60, 160, 230)];
[self addSubview:levelView];
levelView.transform = CGAffineTransformScale(self.transform, .8, .8);
CALayer *layer = levelView.layer;
//DarkDust's 2nd comment
layer.borderWidth = 1;
layer.borderColor = [[UIColor clearColor] CGColor];
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / 1000;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 45.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
layer.transform = rotationAndPerspectiveTransform;
for (NSString *ID in [NSArray arrayWithObjects:@"Level 1", @"Level 2", @"Level 3", @"Level 4", @"Level 5", nil]) {
//Note the offset of 5 from the superview in both X and Y directions. This addresses DarkDusk's first comment
UIControl *ctrl = [[UIControl alloc] initWithFrame:CGRectMake(5, y + 5, levelView.frame.size.width, 220/5)];
[levelView addSubview:ctrl];
[ctrl addTarget:self action:@selector(languageSelected:) forControlEvents:UIControlEventTouchDown];
[self styleEnabled:ctrl];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(13, 0, ctrl.frame.size.width - 13, ctrl.frame.size.height)];
[ctrl addSubview:label];
label.text = ID;
label.font = [UIFont systemFontOfSize:20];
label.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:.8];
label.backgroundColor = [UIColor clearColor];
y += ctrl.frame.size.height;
}
您在图像中看到的级别按钮都是 UIControl
的实例,它们是 UIControl *levelView
的直接子视图。 levelView
是正在转换的视图。
DarkDusk 的另外两个评论专门指的是 UIImages,我没有使用它。如果它们仍然适用并且有人可以解释如何实现它们,我肯定会尝试一下。
I copied the code from the answer to How do I apply a perspective transform to a UIView? in order to achieve the following image. Note, however, the jagged lines separating the levels. Is there away to perform this kind of perspective transformation in a way that anti-aliases these jagged lines?
Edit
I've tried the solutions offered by DarkDust in the comments on this post. None seem to work. Here's my code:
levelView = [[UIControl alloc] initWithFrame:CGRectMake(100, 60, 160, 230)];
[self addSubview:levelView];
levelView.transform = CGAffineTransformScale(self.transform, .8, .8);
CALayer *layer = levelView.layer;
//DarkDust's 2nd comment
layer.borderWidth = 1;
layer.borderColor = [[UIColor clearColor] CGColor];
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / 1000;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 45.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
layer.transform = rotationAndPerspectiveTransform;
for (NSString *ID in [NSArray arrayWithObjects:@"Level 1", @"Level 2", @"Level 3", @"Level 4", @"Level 5", nil]) {
//Note the offset of 5 from the superview in both X and Y directions. This addresses DarkDusk's first comment
UIControl *ctrl = [[UIControl alloc] initWithFrame:CGRectMake(5, y + 5, levelView.frame.size.width, 220/5)];
[levelView addSubview:ctrl];
[ctrl addTarget:self action:@selector(languageSelected:) forControlEvents:UIControlEventTouchDown];
[self styleEnabled:ctrl];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(13, 0, ctrl.frame.size.width - 13, ctrl.frame.size.height)];
[ctrl addSubview:label];
label.text = ID;
label.font = [UIFont systemFontOfSize:20];
label.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:.8];
label.backgroundColor = [UIColor clearColor];
y += ctrl.frame.size.height;
}
The level buttons you see in the image are all instances of UIControl
, and they are the direct subviews of UIControl *levelView
. levelView
is the one that is getting transformed.
The other two of DarkDusk's comments refer specifically to UIImages, which I am not using. If they are still applicable and someone can explain how to implement them, I'll certainly give them a shot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iOS 7 为
CALayer
带来了一个新属性allowsEdgeAntialiasing
,如您所见 此处。当设置为YES
时,您的图层将使用抗锯齿边缘进行变换。iOS 7 brings a new property
allowsEdgeAntialiasing
toCALayer
, as you can see here. When set toYES
, your layer will transform with anti-aliased edges.