我正在開發iOS 5.0+應用程序與最新的SDK。CGAffineTransformMakeRotation移動UILabel
我有一個自定義UIView
(使用自定義XIB)和四UILabel
,我想這個代碼使它們旋轉90度:
- (void)layoutSubviews
{
[self rotateToLandscape];
}
- (void)rotateToLandscape
{
NSLog(@"Label 1: %@", NSStringFromCGRect(self.label1.frame));
NSLog(@"Label 2: %@", NSStringFromCGRect(self.label2.frame));
NSLog(@"Label 3: %@", NSStringFromCGRect(self.label3.frame));
NSLog(@"Label 4: %@", NSStringFromCGRect(self.label4.frame));
self.label1.transform = CGAffineTransformMakeRotation(M_PI/2);
NSLog(@"Label 1: %@", NSStringFromCGRect(self.label1.frame));
self.label2.transform = CGAffineTransformMakeRotation(M_PI/2);
NSLog(@"Label 2: %@", NSStringFromCGRect(self.label2.frame));
self.label3.transform = CGAffineTransformMakeRotation(M_PI/2);
NSLog(@"Label 3: %@", NSStringFromCGRect(self.label3.frame));
self.label4.transform = CGAffineTransformMakeRotation(M_PI/2);
NSLog(@"Label 4: %@", NSStringFromCGRect(self.label4.frame));
}
但是,我不爲什麼,全部住在這相同的位置。
這是日誌,我得到:
Label 1: {{15, 0}, {71, 21}}
Label 2: {{15, 29}, {71, 21}}
Label 3: {{15, 58}, {71, 21}}
Label 4: {{15, 78}, {71, 21}}
Label 1: {{40, -25}, {21, 71}}
Label 2: {{40, 4}, {21, 71}}
Label 3: {{40, 33}, {21, 71}}
Label 4: {{40, 53}, {21, 71}}
我閱讀,我不得不從它的中心旋轉UILabel
(或者從它的左上角),但我不知道該怎麼做。
這就是我得到:
而且,如果我展示中心登錄:
- (void)rotateToLandscape
{
NSLog(@"Label 1: %@", NSStringFromCGPoint(self.label1.center));
NSLog(@"Label 2: %@", NSStringFromCGPoint(self.label2.center));
NSLog(@"Label 3: %@", NSStringFromCGPoint(self.label3.center));
NSLog(@"Label 4: %@", NSStringFromCGPoint(self.label4.center));
self.label1.transform = CGAffineTransformMakeRotation(M_PI/2);
NSLog(@"Label 1: %@", NSStringFromCGPoint(self.label1.center));
self.label2.transform = CGAffineTransformMakeRotation(M_PI/2);
NSLog(@"Label 2: %@", NSStringFromCGPoint(self.label2.center));
self.label3.transform = CGAffineTransformMakeRotation(M_PI/2);
NSLog(@"Label 3: %@", NSStringFromCGPoint(self.label3.center));
self.label4.transform = CGAffineTransformMakeRotation(M_PI/2);
NSLog(@"Label 4: %@", NSStringFromCGPoint(self.label4.center));
}
我得到這個日誌:
Label 1: {50.5, 10.5}
Label 2: {50.5, 39.5}
Label 3: {50.5, 68.5}
Label 4: {50.5, 88.5}
Label 1: {50.5, 10.5}
Label 2: {50.5, 39.5}
Label 3: {50.5, 68.5}
Label 4: {50.5, 88.5}
不旋轉:
這些標籤都在裏面上UIView
,我想我需要旋轉即父視圖,而不是旋轉每個UILabel
。
有什麼建議嗎?輪轉之後,我必須移動每個UILabel
嗎?
謝謝您的回答。正如你所看到的,在這方面很新穎,你知道是否有一個例子可以讓我學習如何做到這一點?謝謝。 – VansFannel 2013-04-08 17:14:10
@VansFannel **什麼是「它」?旋轉轉角?你的代碼中的方法稱爲'rotateToLandscape',但你不應該自己做,只需配置視圖控制器以允許橫向和縱向。 – 2013-04-08 19:26:06
謝謝,但這不能回答我的問題。 – VansFannel 2013-04-08 19:41:06