2012-01-14 306 views
4

我將答案中的代碼複製到How do I apply a perspective transform to a UIView?以獲得以下圖像。但請注意,鋸齒線將水平分開。是否有必要以反鋸齒這些鋸齒線的方式進行這種視角轉換?使用CATransform3DRotate時的抗鋸齒行

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 +反鋸齒旋轉](http://stackoverflow.com/questions/2686027/iphone-calayer-rotate-in-3d-antialias) – DarkDust 2012-01-14 16:11:36

+0

參見重複。你可以通過簡單的做'layer.borderWidth = 1; layer.borderColor = [[UIColor clearColor] CGColor];' – DarkDust 2012-01-14 16:13:41

+0

另請參見[CALayer的抗混疊對角線邊緣](http://stackoverflow.com/questions/6245276/anti-alias-diagonal-edges-of-calayer) – DarkDust 2012-01-14 16:15:47

回答

4

iOS 7帶來了一個新的屬性allowsEdgeAntialiasingCALayer,你可以看到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; 
+0

在plist編輯器中,該值被命名爲「帶邊緣抗鋸齒渲染」。 – 2015-01-29 20:58:28