2011-02-03 71 views

回答

4

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration,你可以应用转换到要不要旋转视图:

view.transform = CGAffineTransformMakeRotation(M_PI/2); 

你可以把这个在动画块,使得它跟随旋转动画:

[UIView setAnimationDuration:duration]; 
[UIView beginAnimations:nil context:NULL]; 
view.transform = CGAffineTransformMakeRotation(M_PI/2); 
[UIView commitAnimations]; 

旋转发生在视图原点周围,这可能使得定位变得棘手。为了正确定位视图,我首先会忽略旋转并确保支柱和弹簧的设置使得视图在没有旋转的情况下处于正确的位置。视图正确定位后,重新启用旋转并调整视图的框架原点,以便视图位于您希望的位置。可以应用平移转换而不是调整框架(转换可以与CGAffineTransformConcat结合使用)。使用哪种方法生成最易读的代码。

要小心,这种视图操作可能会让人困惑。从技术上讲,你不想旋转的视角实际上是旋转的视角!您还可能需要根据开始和结束方向更改旋转量。

0

是否遵循此链接

iPhone app in landscape mode, 2008 systems

或只加这行代码中,要显示在横向模式下

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if(interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
     return YES; 
    } 
    return NO; 
} 
+0

嘿,我想你没有得到我要求的,如果我使用这个代码它支持所有的方向,但我需要防止这种方向只有一个子视图。 – MaheshBabu 2011-02-03 11:49:27

+0

我已经改变了答案。 – Robin 2011-02-03 12:04:38

1

采取的viewController你.m文件一将标记值添加到您想要添加的所有横向视图,并在将它们添加到主视图之前,检查标记值并添加它们。

无论何时调用 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation,都可以通过维护标志来了解当前方向。

0

我通过旋转屏幕并调整视图框架来解决此问题。

if (toorientation == UIInterfaceOrientationPortrait) { 
     sub_view.transform = CGAffineTransformMakeRotation(degreesToRadin(0)); 
    } 
    else if (toorientation == UIInterfaceOrientationPortraitUpsideDown){ 
     sub_view.transform = CGAffineTransformMakeRotation(degreesToRadin(180)); 
    } 
    else if (toorientation == UIInterfaceOrientationLandscapeLeft){ 
     sub_view.transform = CGAffineTransformMakeRotation(degreesToRadin(-90)); 
    } 
    else if (toorientation == UIInterfaceOrientationLandscapeRight){ 
     sub_view.transform = CGAffineTransformMakeRotation(degreesToRadin(90)); 
    }