Я много искал по этому поводу и не могу найти ничего, что могло бы мне помочь.
У меня есть 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 повернется во что угодно.
Мне действительно не помешала бы помощь в этом, спасибо!