我的应用程序显示pdf页面,在纵向模式下显示单个页面(默认模式为纵向)。在旋转到landcscape时,它应该并排显示两页, 在我的ViewController的viewdidloadmethod中添加了以下内容,
- (void)viewDidLoad
{
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
landscape=UIDeviceOrientationIsLandscape(deviceOrientation);
if(landscape)
{
//logic goes here
}
else
{
logic for portrait goes here
}
}
但这对我不起作用,只有肖像逻辑得到了规范。请帮助
答案 0 :(得分:0)
方向更改的处理方式略有不同。 当方向发生变化时,您的viewcontroller需要接收通知。
以下是示例代码:
@implementation PortraitViewController
- (void)awakeFromNib
{
isShowingLandscapeView = NO;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
!isShowingLandscapeView)
{
isShowingLandscapeView = YES;
// logic for landscape orientation goes here
}
else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&
isShowingLandscapeView)
{
isShowingLandscapeView = NO;
// logic for portrait orientation goes here
}
}
有关更多信息,请查看Apple documentation