我一直在搜索这个,找不到任何可以帮助我的东西。
我有一个 UIViewController 包含在另一个 UIViewController 中。当父 UIViewController 旋转时,比如从 Portrait 到 LandscapeLeft,我想让它看起来好像孩子没有旋转。也就是说。无论父母的方向如何,我都希望孩子对天空有相同的方向。如果它的 UIButton 在纵向中是直立的,我希望按钮的右侧在 UIInterfaceOrientationLandscapeLeft 中“向上”。
这可能吗?目前,我正在做这样的事情:
-(void) rotate:(UIInterfaceOrientation)fromOrientation: toOr:(UIInterfaceOrientation)toOrientation
{
if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationLandscapeRight))
|| ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationLandscapeLeft)))
{
}
if(((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
|| ((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationPortrait)))
{
}
if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationLandscapeLeft))
|| ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationLandscapeRight)))
{
}
if(((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
|| ((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationPortrait)))
{
}
if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
|| ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationPortrait)))
{
}
if(((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationLandscapeRight))
|| ((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationLandscapeLeft)))
{
}
}
这似乎是对代码的完美浪费。此外,我计划使用 CGAffineTransform (如在此处引用:http ://www.crystalminds.nl/?p=1102 )但我对是否应该更改视图的尺寸以匹配旋转后的尺寸感到困惑.
这里最大的噩梦是您必须跟踪全局“方向”变量。如果你不这样做,错觉就会消失,并且 ViewController 会旋转成任何东西。
我真的可以在这方面使用一些帮助,谢谢!