我一直在寻找这个了很多,并不能找到任何帮助我。

我有一个UIViewController包含在另一个的UIViewController内。当父的UIViewController旋转,从人像到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 ),但我感到困惑我是否应该改变视图的尺寸相匹配,他们会是怎样旋转后。

这里最大的噩梦是,你必须跟踪一个全球性的“方向”变量。如果你不这样做,幻觉消失,并在视图控制器旋转到什么。

我真的可以使用一些这方面的帮助,谢谢!

有帮助吗?

解决方案

你能做的最好的事情是根据乌拉圭回合的接口方向来更改子视图帧的帧。你可以不喜欢它:

 #pragma mark -
 #pragma mark InterfaceOrientationMethods

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
        //self.view = portraitView;
        [self changeTheViewToPortrait:YES andDuration:duration];

    }
    else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
        //self.view = landscapeView;
        [self changeTheViewToPortrait:NO andDuration:duration];
    }
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

- (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];

    if(portrait){
        //change the view and subview frames for the portrait view
    }
    else{   
        //change the view and subview  frames for the landscape view
    }

    [UIView commitAnimations];
}

希望这有助于。

其他提示

我意识到的东西..让我们说我们的项目有视图控制器的多层(如如果添加其他视图控制器子视图您的视图控制器)

willRotateToInterfaceOrientation:持续时间的方法将不被调用的ViewController的第二层...

所以我所做的是,后我从最顶层初始化我的第二层的视图控制器,则当willRotateToInterfaceOrientation:持续时间的方法被称为最顶层上,我会请willRotateToInterfaceOrientation:持续时间第二层视图控制器如井

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top