3

我需要的很简单:无论设备如何旋转,我都希望我的 UICollectionView 框架始终填满屏幕。

现在,我通过使用“willAnimateRotationToInterfaceOrientation:...”方法并调用一个在旋转时重新创建集合视图的方法来完成此操作。但是,这会导致视图在旋转时闪烁,因为旧视图被删除并添加了新视图。

所以我知道我需要使用自动布局或支柱和弹簧,我想使用后者。我知道如何使用界面生成器设置支柱和弹簧,但我正在处理的项目没有使用笔尖或情节提要。

这是我创建集合视图的方法(在 viewDidLoad 中调用),包括我拥有的不起作用的代码:

 - (void)sceneSetup
 {
     CGFloat cvWidth;
     CGFloat cvHeight;

 if ([self getCurrentInterfaceOrientation] || [self getCurrentDeviceOrientation]) {
     self.orientationIsLandscape = YES;
     cvWidth = 1024;
     cvHeight = 768;

 }   else {
        self.orientationIsLandscape = NO;
        cvWidth = 768;
        cvHeight = 1024;
    }

     EmailsLayout *layout = [[EmailsLayout alloc]init];
     [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
     self.emailsCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, cvWidth, cvHeight) collectionViewLayout:layout];

     //here is my attempt to programmatically set struts and springs
     self.view.autoresizesSubviews = YES;
     self.emailsCollectionView.autoresizingMask = (UIViewAutoresizingFlexibleWidth & 
         UIViewAutoresizingFlexibleHeight & UIViewAutoresizingFlexibleLeftMargin & 
          UIViewAutoresizingFlexibleRightMargin & UIViewAutoresizingFlexibleTopMargin & 
           UIViewAutoresizingFlexibleBottomMargin); 

     self.emailsCollectionView.dataSource = self;
     self.emailsCollectionView.delegate = self;
     [self.emailsCollectionView setScrollEnabled:YES];
     self.emailsCollectionView.userInteractionEnabled = YES;
     self.emailsCollectionView.pagingEnabled = YES;
     self.emailsCollectionView.backgroundColor = UIColorFromRGB(0x262d32);
     [self.emailsCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:cellIdentifierEmails];
     [self.emailsCollectionView reloadData];

     [self.view addSubview:self.emailsCollectionView];
}

不知道我做错了什么。任何帮助表示赞赏。

4

1 回答 1

2

尝试使用or |将多个autoresisingMask值组合在一起,而不是and &

于 2013-08-15T17:26:16.553 回答