我將答案中的代碼複製到How do I apply a perspective transform to a UIView?以獲得以下圖像。但請注意,鋸齒線將水平分開。是否有必要以反鋸齒這些鋸齒線的方式進行這種視角轉換?使用CATransform3DRotate時的抗鋸齒行
編輯 我試着通過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,我不使用它。如果他們仍然適用,有人可以解釋如何實施他們,我一定會給他們一個鏡頭。
的可能重複的[iPhone:CALayer的+在3D +反鋸齒旋轉](http://stackoverflow.com/questions/2686027/iphone-calayer-rotate-in-3d-antialias) – DarkDust 2012-01-14 16:11:36
參見重複。你可以通過簡單的做'layer.borderWidth = 1; layer.borderColor = [[UIColor clearColor] CGColor];' – DarkDust 2012-01-14 16:13:41
另請參見[CALayer的抗混疊對角線邊緣](http://stackoverflow.com/questions/6245276/anti-alias-diagonal-edges-of-calayer) – DarkDust 2012-01-14 16:15:47