2012-01-08 51 views
4

我做了一个iPad应用的开始,LandscapeOrientation对目标C didload方法

当我载入我在纵向模式下的应用程序的第一次,但是当我在横向模式下加载我的应用程序的正常工作第一次只拍摄肖像模式的坐标,因为在我的didLoad方法中,我只给出肖像模式的坐标。

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

我想这一点,我didLoad方法

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

里面,但我无法写状态的的if/else里面我didLoad方法。

我该怎么办?

回答

2
-(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()方法,

3

你可以做如下处理 -

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

}

0

我有类似的issue与UIScrollView的。我通过按照建议here调整子视图来解决问题。

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