旋转后,整个视图从右侧移动

nautem 发布于 5 天前 ios 最后更新 5 天前 0 浏览

我的主屏幕如下所示。我已经使用Storyboard和尺寸类来设计屏幕,在这个屏幕集合视图中用于显示数据。

Screen1 如果使用导航控制器导航至任何屏幕,则旋转上述主屏幕后,整个视图将从右侧移动(使用下图中的红色线显示的区域)。只有当我旋转第一个屏幕时,才会发生这种情况,否则一切都会好起来,并且我没有在主屏幕的“viewWillTransitionToSize”事件(第一屏幕截图)内写入任何内容。 enter image description here 我使用“ViewDidLoad”方法中的“NSLog”检查了第二个屏幕的高度和宽度,这是正确的。但为什么屏幕从右侧移开? 我已经使用下面的代码在主屏幕(屏幕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;
}
已邀请:

lquia

赞同来自:

我看起来像collectionView没有填充其父级,所以你需要找到它的父级的高度和宽度,并为这个布局设置这些值,

[UIScreen mainScreen].bounds.size.width
知道屏幕的大小,只需将UICollectionView的框架设置为刚刚想出的宽度即可。