2012-01-08 29 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); 
}