【发布时间】:2014-12-28 19:23:35
【问题描述】:
我必须绘制一个菜单,其部分必须支持仅在 iPad 上旋转。
当我第一次在设备上启动应用程序时,即使设备处于纵向或横向模式,一切都很好。
旋转后,我收到错误大小的包含单元格的视图。
-(void)buildMenu:(UIInterfaceOrientation)interfaceOrientationValue{
CGFloat padding = 1;
CGFloat widthCell = 0;
CGFloat heightCell = 0;
int rowNo = 0;
int columnsNo = 0;
int goToNextRow = 0; // used when we draw the menu - start drawing cell to the next row in menu
if((interfaceOrientationValue == UIDeviceOrientationLandscapeRight) || (interfaceOrientationValue == UIDeviceOrientationLandscapeLeft)){//iPad Landscape - FH only for iPad support rotation
rowNo = kLandscapeColumns; // 2
columnsNo = kLandscapeRows; // 3
widthCell = (self.viewMenuArea.frame.size.width/columnsNo-rowNo*padding);
heightCell = (self.viewMenuArea.frame.size.height/rowNo-padding);
goToNextRow = columnsNo; // go to the next line/row when we were draq the cell 4.
}else{//iPad || iPhone - Portrait
rowNo = kPortraitRows; //2
columnsNo = kPortraitColumns; //3
widthCell = (self.viewMenuArea.frame.size.width/rowNo-padding);
heightCell = (self.viewMenuArea.frame.size.height/columnsNo-padding);
goToNextRow = rowNo; // go to the next line/row when we were draq the cell 3.
}
//Draw Menu Cells
CGFloat x = 0;
CGFloat y = 0;
int itemsCount = 1;
for(int i=0; i<self.dataSource.count; i++){
[FHMenuCell buildMenuCell_initWithTitle:[self.dataSource objectAtIndex:i] isDisabled:NO xOrigin:x yOrigin:y width:widthCell height:heightCell pendingItems:0 owner:self container:self.viewMenuArea delegate:self tag:i];
if (itemsCount % goToNextRow == 0){
y += heightCell + padding;
x = 0;
}else{
x += widthCell+padding;
}
itemsCount++;
}
}
我在viewwillappear 中调用此方法,然后当用户在didRotateFromInterfaceOrientation 中旋转设备时。
我在 xib 中添加了一个带有 self.viewMenuArea 的打印屏幕。
关于包含单元格的正确视图框架的任何建议 (self.viewMenuArea)?
【问题讨论】:
标签: ios rotation resize frame screen-rotation