繁体   English   中英

iOS:如何更改UICollectionViewCell的方向?

[英]iOS: How can I change the orientation of a UICollectionViewCell?

我有一个UICollectionViewController ,我在用户转动iPad时将其加载到横向。 我遇到的问题是我的UICollectionViewCell仍然像纵向一样加载。 我在接口生成器中将UICollectionViewController设置为landscape,我正在使用我称为CollectionViewCell的自定义单元类。 每个单元格只包含一个图像和一个标签。

我是否应该在Interface Builder或我的代码中做些什么? 我尝试使用CGAffineTransformationMakeRotation ,但这没有用。 如果其他人之前遇到过这种情况,我将非常感激! 非常感谢!

这里有一些参考代码:

-(void)viewDidLoad
{
 self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
}

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section
{
    return listArray.count;
}

- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView
{
    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{      
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"devices" forIndexPath:indexPath];
   cell.statusImage.image=[UIImage imageNamed:@"Default.png"];
    cell.name.text=@"HEY !!!!!";
    return cell;
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(320, 420);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(50, 20, 50, 20);

}

如果其他人遇到这个问题,我就是这样解决的。

我最初不允许自动旋转,而只是使用NSNotificationCenter注册orientationChanged通知。 这很好用,除了它阻止我的第二个视图意识到它需要以横向模式加载。

所以不是那样,我已经为我的主视图嵌入的tabBar创建了一个类,并且我为该类和所有其他视图中的shouldAutoRotate方法返回NO ,除了我想在横向模式下加载的那个。 我仍然在主视图'' tabBar控制器中使用orientationChanged通知,因为它嵌入在tabBar 但是我只是在返回主视图时使用自动旋转。

如果有人有任何疑问,请告诉我。 希望能帮助到你!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM