2011-11-21 44 views
2

我正在制作一个iPad应用程序。在这个应用程序中,我使用DetailViewController中的表格视图,我添加了一个逻辑,表格视图根据内容调整其高度。内容制作为标签,然后添加到表格视图单元格中。我已将标签的宽度设置为680px。它在纵向模式下正常工作,但我必须在横向模式下设置615px。如何以编程方式在iPad中定位?

我怎样才能知道iPad的方向,然后使用if语句来设置标签宽度。

我以前CGFloat width = CGRectGetWidth(self.view.bounds);得到宽度viewWillAppear。但如果我的应用程序在运行人像,然后它会给宽度肖像,但是当我去到风景模式我收到没有宽度。请告诉我可以在什么地方放置上面的线,以便在任何时候在纵向和横向都可以获取宽度,或者如果有任何其他的方法来获取这个宽度。

+0

可能重复[iphone/ipad方向处理](http://stackoverflow.com/questions/2815802/iphone-ipad-orientation-handling) – Nasreddine

回答

0
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    [self adjustViewsForOrientation:toInterfaceOrientation]; 
} 

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation { 
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { 
     titleImageView.center = CGPointMake(235.0f, 42.0f); 
     subtitleImageView.center = CGPointMake(355.0f, 70.0f); 
     ... 
    } 
    else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { 
     titleImageView.center = CGPointMake(160.0f, 52.0f); 
     subtitleImageView.center = CGPointMake(275.0f, 80.0f); 
     ... 
    } 
} 
0

使用statusBarOrientation,因为有时装置取向可以改变,但在状态栏不会(例如,当该设备可以是平坦的桌子上)。

if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) 
{ 
    adjWidth = 480.0; 
} 
else 
{ 
    adjWidth = 320.0; 
} 
相关问题