我的主屏幕如下图所示。我使用了Storyboards和size类来设计屏幕,这里的屏幕集合视图用于显示数据。
如果我使用导航控制器导航到任何屏幕,旋转上面的主屏幕后,整个视图将从右侧移动(使用下面屏幕截图中的红线显示的区域)。只有当我旋转第一个屏幕时才会发生这种情况,否则一切都会好的,而且我没有在" viewWillTransitionToSize"主屏幕的事件(第一次截图)。
我使用" NSLog"检查了第二个屏幕的高度和宽度。在" ViewDidLoad"方法,它是正确的。但为什么屏幕会从右侧移开?
我已使用以下代码在主屏幕(屏幕1)中使用UICollectionView加载数据。
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return arrDashBoardList.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView1 cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
//static float fltAlpha =1.0f;
UICollectionViewCell *cell = [collectionView1 dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UILabel *lblIcon = (UILabel *)[cell viewWithTag:100];
lblIcon.font = [UIFont fontWithName:chsIcons size:160];
lblIcon.textColor = [UIColor colorWithRed:65.0f/255.0f green:168.0f/255.0f blue:119.0f/255.0f alpha:1.0f];
lblIcon.text =[arrDashBoardImages objectAtIndex:indexPath.row];
UILabel *lblModule = (UILabel *)[cell viewWithTag:101];
lblModule.text = [arrDashBoardList objectAtIndex:indexPath.row];
lblModule.font =[UIFont fontWithName:KlavikaRegular size:25];
lblModule.textAlignment = NSTextAlignmentCenter;
lblModule.textColor = [UIColor blackColor];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView1 didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:STORYBOARD_MAIN bundle:nil];
NavigationViewController_iPhone *navigationController = [storyboard instantiateViewControllerWithIdentifier:@"contentController"];
if([[arrDashBoardList objectAtIndex:indexPath.row] caseInsensitiveCompare:@“abc”] == NSOrderedSame) //Events
{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:STORYBOARD_DASHBOARD bundle:nil];
ABCViewController_iPad *controller = [storyboard instantiateViewControllerWithIdentifier:@"abcController"];
navigationController.viewControllers = @[controller];
}
else if([[arrDashBoardList objectAtIndex:indexPath.row] caseInsensitiveCompare:@“xyz”] == NSOrderedSame)//Active Floats
{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:STORYBOARD_DASHBOARD bundle:nil];
XYZViewController_iPad *controller = [storyboard instantiateViewControllerWithIdentifier:@“xyzController"];
navigationController.viewControllers = @[controller];
}
self.frostedViewController.contentViewController = navigationController;
}
答案 0 :(得分:0)
我看起来像collectionView没有填充其父级,所以你需要找到它的父级的高度和宽度,并为这个布局设置这些值,
[UIScreen mainScreen].bounds.size.width
知道屏幕的大小,只需将UICollectionView的框架设置为刚刚想出的宽度。