2012-04-27 62 views
1

我有我的UIView像textfields,标签,表,按钮上的几个组件。我想处理设备方向更改。 如何使这些组件自动安排在正确的位置?或者我需要重新设计它们?如何在iPhone/iPad的设备方向更改时处理UI组件?

请帮忙。

感谢

+0

Dup的的 - http://stackoverflow.com/questions/2815802/iphone-ipad-orientation-handling – rishi 2012-04-27 04:42:54

+1

2选项:(1)复位的每帧和每一个部件或( 2)具有不同方向的XIB。非常普遍的问题。你会通过搜索它找到解决方案。干杯。 – viral 2012-04-27 04:48:02

回答

3

enter image description here您可以使用自动调整大小选项的方向的变化。无需编写一行代码。

+1

hm ..只调整界面构建器中的组件。不需要代码。如果你在IB中有一个标签,选择标签并点击大小检查器。你可以在那里看到自动修复图。尝试删除这些红线,并检查横向和纵向模式下的方向是否正确。如果不正确,请尝试更改/删除其他任何红线。它至少在一个位置处于正确的位置。您必须构建并检查每次获取正确的结果。希望你明白。如果有任何疑问让我知道 – 2012-04-27 05:32:48

+1

看到附上的屏幕截图 – 2012-04-27 05:37:51

+0

非常感谢!这就像一个魅力! – iOSDev 2012-04-30 01:29:38

4
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
[self adjustViewsForOrientation:toInterfaceOrientation]; 
} 

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation { 
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { 

    // set you subviews,Label button frame here for landscape mode,, 
} 
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { 
    // set you subviews,Label button frame here for portrait-mode, 
} 
} 

//不要忘了添加此Delegate方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ 
    // Return YES for supported orientations 
    return YES; 
} 

希望,这将帮助你..

+0

非常有用! – iOSDev 2012-04-30 02:31:25

1

尝试此

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 


    if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     // portrait Arrangement 
    }  
    else 
    { 
     // Landscape Arrangement 
    } 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || 
      interfaceOrientation == UIInterfaceOrientationPortrait || 
      interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
      interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
}