使用CATransform3DRotate旋转时抗锯齿线条

4
我从如何将透视变换应用于UIView?的答案中复制了代码,以实现以下图像。然而,请注意分隔级别的锯齿状线条。有没有一种方法可以以一种反锯齿的方式执行这种透视变换? enter image description here 编辑:我尝试了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,但我没有使用它们。如果它们仍然适用,并且有人可以解释如何实现它们,我一定会尝试。

1
可能是重复的问题:iPhone:CALayer + 3D旋转+抗锯齿? - DarkDust
请参考重复内容。您可以通过简单地执行 layer.borderWidth = 1; layer.borderColor = [[UIColor clearColor] CGColor]; 来成功。 - DarkDust
最后但并非最不重要的:旋转UIImageView的任何快速而简单的抗锯齿技术 - DarkDust
1个回答

4

iOS 7引入了一个新属性allowsEdgeAntialiasingCALayer中,您可以在这里看到。当设置为YES时,您的图层将具有反锯齿边缘。

/* When true this layer is allowed to antialias its edges, as requested
 * by the value of the edgeAntialiasingMask property.
 *
 * The default value is read from the boolean UIViewEdgeAntialiasing
 * property in the main bundle's Info.plist. If no value is found in
 * the Info.plist the default value is NO. */

@property BOOL allowsEdgeAntialiasing;

在plist编辑器中,此值被命名为“使用边缘抗锯齿渲染”。 - Ben Flynn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接