【发布时间】:2013-11-17 21:19:37
【问题描述】:
您好,我正在开发包含纵向和横向方向的 iphone 应用程序(不适用于 ipad)。我的问题是有时没有完成定位。如果我将设备切换到横向模式,它只会停留在该模式,而不是切换到纵向模式,反之亦然。
我不知道问题所在。我在部署信息部分激活了所有设备方向模式。
谁能告诉我解决办法。
提前致谢, 马赫什。
【问题讨论】:
您好,我正在开发包含纵向和横向方向的 iphone 应用程序(不适用于 ipad)。我的问题是有时没有完成定位。如果我将设备切换到横向模式,它只会停留在该模式,而不是切换到纵向模式,反之亦然。
我不知道问题所在。我在部署信息部分激活了所有设备方向模式。
谁能告诉我解决办法。
提前致谢, 马赫什。
【问题讨论】:
-(void)viewWillAppear:(BOOL)animated
{
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)
{
// Write your orientation code here.
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
// Write your orientation code here.
}
}
// For ios5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)
{
// Write orientation code here for ios5
}
else if (interfaceOrientation ==UIInterfaceOrientationLandscapeLeft||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
// Write orientation code here for ios5
}
return UIInterfaceOrientationMaskAll;
}
// Write code for ios6 and above
-(BOOL)shouldAutorotate
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
return YES;
}
else
return NO;
}
-(void)viewWillLayoutSubviews
{
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)
{
// Write orientation code here for ios5
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
// Write orientation code here for ios5
}
}
【讨论】: