我做了一个 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/