[英]Device orientation handling in iOS 6 during view load?
我有一个Tab栏应用程序。 我正在使用XCode 4.3.3。 我用iOS6的东西升级到了4.5.2。
我在每个视图的shouldAutorotateToInterfaceOrientation
代码将检查当前的设备方向并正确放置所有UI组件。
但升级到iOS 6后,此代码未执行。 我已经尝试了差不多一天来解决这个问题,但没有运气。
我也试过了
UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
在viewLoad
, viewDidLoad
, viewWillAppear
如果我想在视图加载期间检查方向,并在视图加载期间将UI组件放置到适当的位置,我该怎么办? 请提出你的建议。
谢谢
如果你想检查哪个是当前方向,那么你只需要写下prifix.pch下面的行
#define isPortrait [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown
然后你要检查方向,写下如下条件
if(isPortrait)
{
//portrait mode....
}
else
{
//landscape mode....
}
让我知道它的工作与否......
快乐的编码!
要检查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;
}
并在ViewWillApear
设备中每次检查Oriantation,如: -
- (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];
}
UPDATE
可能人们使用检查设备orientation
如下所示将此行放入ViewWillApear
: -
[[UIApplication sharedApplication] statusBarOrientation];
[[UIDevice currentDevice] orientation];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceRotated:) name:UIDeviceOrientationDidChangeNotification object:nil];
和
-(void)deviceRotated:(NSNotification*)notification
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
//Do your stuff for landscap
}
else if(orientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
//Do your stuff for potrait
}
}
在viewDidLoad方法中,您需要检查相同的内容,因此您需要编写代码,除非它可能影响视图(如果它不在纵向上)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.