Iphone 查看加载期间iOS 6中的设备方向处理?
我有一个选项卡栏应用程序。我使用的是XCode 4.3.3。我已经用iOS6升级到了4.5.2 每个视图的Iphone 查看加载期间iOS 6中的设备方向处理?,iphone,ios,ipad,ios6,Iphone,Ios,Ipad,Ios6,我有一个选项卡栏应用程序。我使用的是XCode 4.3.3。我已经用iOS6升级到了4.5.2 每个视图的shouldAutorotateToInterfaceOrientation中的我的代码将检查当前设备方向,并正确放置所有UI组件 但升级到iOS 6后,此代码不会执行。我已经尝试了将近一天来解决这个问题,但没有成功 我也试过了 UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
shouldAutorotateToInterfaceOrientation
中的我的代码将检查当前设备方向,并正确放置所有UI组件
但升级到iOS 6后,此代码不会执行。我已经尝试了将近一天来解决这个问题,但没有成功
我也试过了
UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
在viewLoad
,viewDidLoad
,视图将出现
如果我想在视图加载期间检查方向,并在视图加载期间将UI组件放置到适当的位置,我应该怎么做。请给出你的建议
感谢在ios6中检查方向,您必须在下面的方法中填写,并且在info.plist中您必须定义您想要的方向
让我知道它是否工作
编码快乐
- (BOOL)shouldAutorotate{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;//you can write here which ever orientation you want..
}
您可以通过以下方式管理Oriantation:-
-(BOOL)shouldAutorotate
{
return YES;
}
并在视图中每次检查willapear
设备或安装,如:-
- (void)willRotateToOrientation:(UIInterfaceOrientation)newOrientation {
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
if (newOrientation == UIInterfaceOrientationLandscapeLeft || newOrientation == UIInterfaceOrientationLandscapeRight) {
//set your landscap View Frame
[self supportedInterfaceOrientations];
}
}
else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
if(newOrientation == UIInterfaceOrientationPortrait || newOrientation == UIInterfaceOrientationPortraitUpsideDown){
//set your Potrait View Frame
[self supportedInterfaceOrientations];
}
}
// Handle rotation
}
-(void)viewWillAppear:(BOOL)animated
{
[self willRotateToOrientation:[[UIDevice currentDevice] orientation]];
[super viewWillAppear:YES];
}
更新
可能有人会使用下面类似的检查设备将这一行输入到视图中:-
[[UIApplication sharedApplication] statusBarOrientation];
[[UIDevice currentDevice] orientation];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceRotated:) name:UIDeviceOrientationDidChangeNotification object:nil];
及
若要检查哪个是当前方向,则只需在第行下方的prifix.pch中写入
#define isPortrait [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown
然后在要检查方向的地方,写下如下条件
if(isPortrait)
{
//portrait mode....
}
else
{
//landscape mode....
}
让我知道它是否有效
快乐编码 在viewDidLoad方法中,您需要检查相同的代码,因此您需要编写代码,除非它可能会影响视图(如果它不在纵向视图中)。检查此链接:同时检查此链接:我添加了此代码,但这并没有解决我的问题。加载viewController时调用supportedInterfaceOrientations方法,但在那里我无法使用UIDeviceOrientation interfaceOrientation=[[UIDevice currentDevice]orientation]找到方向;您是否在info.plist文件中添加了方向???添加您希望在设备中支持的方向非常重要,这也完成了,但我的问题是在视图加载期间查找接口方向。以前我在shouldAutorotateToInterfaceOrientation中做我需要的工作。现在没有这样的委托方法..:(你是对的,这是唯一的解决方案。考虑过给出我的答案。你做了..很好。我接受你的答案。但它在运行时设备定向中不起作用….当视图在当时导航到另一个视图时,它只会起作用,否则它不会调用这些方法。。。。
if(isPortrait)
{
//portrait mode....
}
else
{
//landscape mode....
}