2011-06-08 70 views
1

我正在开发支持横向和纵向orientation.I两个不同的笔尖文件为我的rootviewController iPad应用程序。以下是该问题的场景 -
1.在portait模式下从根视图中选择一个项目,以纵向推送下一个视图。
2.转动设备
3.按导航栏上的后退按钮
该视图从堆栈加载的是rootViewController的portait视图。设备仍处于横向模式。
请建议解决方案来处理上述问题。
另外,请在处理设备旋转时建议遵循的最佳做法。UINavigationController在横向和纵向模式下导航的最佳做法

回答

1

以下列方法使用通知,并设置receivedRotate方法中的坐标。

-(void)viewWillAppear:(BOOL)animated 
{ 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil]; 
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

} 

-(void)viewWillDisappear:(BOOL)animated 
{ 
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; 
} 

例如在receivedRotate你可以设置你的tableview的坐标为:

if (orientation == UIDeviceOrientationLandscapeLeft||orientation==UIDeviceOrientationLandscapeRight) 
    { 
     [tblView reloadData]; 
     tableX=70.0; 

    } 
    else 
    { 
     [tblView reloadData]; 
     tableX=48.0; 
} 

也叫recieveRotate在viewDidLoad中这是非常重要

+0

感谢nitish的详细答案。它类似于iAmitwagh精神超过 – amavi 2011-06-08 11:31:31

+1

是的。但我之前发布它:) – Nitish 2011-06-08 11:33:37

1

检查这种方法,可能会帮助ü...

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations. 
return ( 
     interfaceOrientation == UIInterfaceOrientationPortrait 
     || interfaceOrientation == UIInterfaceOrientationLandscapeLeft 
     || interfaceOrientation == UIInterfaceOrientationLandscapeRight 
     || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown 
     );} 

或尝试设置autoresizingMask的控制器希望这将有助于ü。

+0

我回来是支持所有的旋转。你可以把一些光autoresizingMask?如何以及在哪里设置? – amavi 2011-06-08 09:56:27

+0

其UIComponent的属性。你可以将它设置为UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight。它会根据方向自动调整UI组件的宽度和高度。 – 2011-06-08 09:58:48

1

您需要在运行时方法 检查方向 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

} &变化根据定向视图的元素。

+0

感谢Amit.It协同实现 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation持续时间:(NSTimeInterval)持续时间方法来处理旋转。 – amavi 2011-06-08 11:30:47

相关问题