以编程方式设置Struts和Springs以在旋转时保持UIView全屏

时间:2013-08-15 17:05:24

标签: ios autoresizingmask

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

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

所以我知道我需要使用autolayout或struts和spring,我想使用后者。我知道如何使用界面构建器设置struts和spring,但我正在处理的项目不使用nib或storyboard。

这是我创建集合视图的方法(在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];
}

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

1 个答案:

答案 0 :(得分:2)

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