如果我们向窗口添加任何对象,然后我们想改变方向,那么我们必须使用变换方法。
#define DegreesToRadians(degrees) (degrees *M_PI /180)
添加上面的行
CGAffineTransform newTransform;
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
switch (orientation)
{
case UIInterfaceOrientationPortraitUpsideDown:
newTransform = CGAffineTransformMakeRotation(-DegreesToRadians(180));
txt.transform = newTransform;
txt.frame = CGRectMake(0, 0, 320, 480);
break;
case UIInterfaceOrientationLandscapeLeft:
newTransform = CGAffineTransformMakeRotation(DegreesToRadians(-90));
txt.transform = newTransform;
txt.frame = CGRectMake(0, 0, 320, 480);
break;
case UIInterfaceOrientationLandscapeRight:
newTransform = CGAffineTransformMakeRotation(DegreesToRadians(90));
txt.transform = newTransform;
txt.frame = CGRectMake(0, 0, 320, 480);
break;
default:
newTransform = CGAffineTransformMakeRotation(-DegreesToRadians(0));
txt.transform = newTransform;
txt.frame = CGRectMake(0, 0, 320, 480);
break;
}
这里 txt 是对象名,这样试试。