使用CATransform3DRotate时的抗锯齿线

时间:2012-01-14 15:49:21

标签: iphone ios cocoa-touch transform catransform3d

我将答案中的代码复制到How do I apply a perspective transform to a 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 个答案:

答案 0 :(得分:4)

iOS 7为allowsEdgeAntialiasing带来了新属性CALayer,您可以看到here。设置为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;