在目标c中启动didload方法的LandscapeOrientation

我做了一个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 adjustViewtForNewOrientation: self.interfaceOrientation]; } -(void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation duration: (NSTimeInterval) duration { [self adjustViewtForNewOrientation: interfaceOrientation]; } - (void) adjustViewtForNewOrientation: (UIInterfaceOrientation) orientation { if (UIInterfaceOrientationIsLandscape(orientation)) { // Do some stuff } else { // Do some other stuff } 

adjustViewtForNewOrientation在ViewDidLaod()方法中调用adjustViewtForNewOrientation

您可以按以下方式进行处理 –

 -(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 } 

}

我有与UIScrollView类似的问题 。 我通过调整这里建议的子视图来修复它。

 - (void)alignSubViews { // Position all the content views at their respective page positions scrollView.contentSize = CGSizeMake(self.contentViews.count * scrollView.bounds.size.width, scrollView.bounds.size.height); NSUInteger i = 0; for (UIView *v in self.contentViews) { v.frame = CGRectMake(i * scrollView.bounds.size.width, 0, scrollView.bounds.size.width, scrollView.bounds.size.height); i++; } } - (void)viewDidLoad { [super viewDidLoad]; //Setup subviews and then align the views. [self alignSubViews]; } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { [self alignSubViews]; scrollView.contentOffset = CGPointMake(self.currentPage * scrollView.bounds.size.width, 0); }