Линии сглаживания при использовании CATransform3DRotate - PullRequest
4 голосов
/ 14 января 2012

Я скопировал код из ответа в Как применить перспективное преобразование к 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 Ответ

4 голосов
/ 22 сентября 2014

iOS 7 приносит новое свойство allowsEdgeAntialiasing в CALayer, как вы можете видеть здесь .Когда установлено значение 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;
...