首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >heightForRowAtIndexPath无法识别方向

heightForRowAtIndexPath无法识别方向
EN

Stack Overflow用户
提问于 2012-10-30 17:20:12
回答 2查看 232关注 0票数 1

我有一个tableView,我必须根据设备是纵向还是横向来定义不同的单元高度,但这种方法似乎无法识别设备的方向。此方法不起作用:

代码语言:javascript
复制
  -(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{


  UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice]orientation];//here doesn't recognize the orientation


 if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){
     if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation== UIInterfaceOrientationPortraitUpsideDown) {
         self.tableView.rowHeight =33.33333;

     }
     else if (deviceOrientation== UIInterfaceOrientationLandscapeRight || deviceOrientation==UIInterfaceOrientationLandscapeLeft){

         self.tableView.rowHeight = 16.333333;
     }
 }

 else {
     if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation== UIInterfaceOrientationPortraitUpsideDown){
         self.tableView.rowHeight = 66.66666;

     }else if (deviceOrientation== UIInterfaceOrientationLandscapeRight || deviceOrientation==UIInterfaceOrientationLandscapeLeft){
         self.tableView.rowHeight = 33.333333;

     }

 }
 return self.tableView.rowHeight;

}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-30 17:44:11

使用:

代码语言:javascript
复制
UIDeviceOrientation deviceOrientation = [UIApplication sharedApplication].statusBarOrientation;

要识别statusBar方向,请执行以下操作:

代码语言:javascript
复制
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice]orientation];
票数 0
EN

Stack Overflow用户

发布于 2012-10-30 18:26:58

使用单例类方法UIDeviceOrientation deviceOrientation = UIApplication sharedApplication.statusBarOrientation];

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13135906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档