iphone - objective-c 中 didload 方法启动时的 LandscapeOrientation

标签 iphone ios ipad uiinterfaceorientation viewdidload

我做了一个 iPad 应用程序,

当我第一次以纵向模式加载我的应用程序时它工作正常,但是当我第一次以横向模式加载我的应用程序时,它只采用纵向模式的坐标,因为在我的 didLoad 方法我只给出纵向模式的坐标。

现在需要在我的 didLoad 方法中提供横向模式的坐标。

我在我的 didLoad 方法中试过了

if (interfaceOrientation == UIInterfacePortraitmode ||
    interfaceOrientation == UIInterfaceUpsideDown)
{
    // do this....
}
else
{
    // do this....
}

但我无法在我的 didLoad 方法中编写 if/else 的条件。

我该怎么办?

最佳答案

你可以做如下处理 -

-(void) viewWillAppear: (BOOL) animated {
       [super viewWillAppear: animated];
       [self updateLayoutForNewOrientation: self.interfaceOrientation];
}

-(void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation duration: (NSTimeInterval) duration {
       [self updateLayoutForNewOrientation: interfaceOrientation];
}

最后是自定义方法 -

- (void) updateLayoutForNewOrientation: (UIInterfaceOrientation) orientation {
    if (UIInterfaceOrientationIsLandscape(orientation)) {
         // Do some stuff
    } else {
         // Do some other stuff
    }

关于iphone - objective-c 中 didload 方法启动时的 LandscapeOrientation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8775911/

相关文章:

ios - ios8 中 uialertview 中的复选框

ios - 代码 8 : Build app with iOS 9 Base SDK

应用商店可以接受 iPhone 通过数据库更新 UI 内容吗?

iphone - 在 iPhone 中检索 Outlook 联系人

IOS/ Storyboard/自动布局 : Center round button under horizontal bar

html - 仅在 Ipad 上随机换行

iphone - 在 iOS 中用手指绘制贝塞尔曲线?

IOS 应用程序无线分发 : error when download can't connect to domain

ios - 展平任意数组

objective-c - iPad 纵向中 <UITableView> 的开始/结束外观转换调用不平衡