【问题标题】:Anti-aliasing lines when using CATransform3DRotate使用 CATransform3DRotate 时消除锯齿线
【发布时间】:2012-02-10 09:45:46
【问题描述】:

我将答案中的代码复制到How do I apply a perspective transform to a UIView? 以实现以下图像。但是请注意,锯齿线分隔各个级别。是否有办法以消除锯齿状线条的方式执行这种透视变换?

编辑 我已经在这篇文章的 cmets 中尝试了 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 的另外两个 cmets 专门指 UIImages,我没有使用它。如果它们仍然适用并且有人可以解释如何实现它们,我一定会试一试。

【问题讨论】:

标签: iphone ios cocoa-touch transform catransform3d


【解决方案1】:

iOS 7 为CALayer 带来了一个新属性allowsEdgeAntialiasing,如您所见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;

【讨论】:

  • 在 plist 编辑器中,这个值被命名为“Renders with edge antialiasing”。
猜你喜欢
  • 2017-01-02
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多