我正在使用最新的 SDK 开发 iOS 5.0+ 应用程序。
我有一个自定义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
旋转后我必须移动每个吗?