如何更改 UICollectionView 中的滚动方向? [英] How can I change the scroll direction in UICollectionView?

查看:24
本文介绍了如何更改 UICollectionView 中的滚动方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在基于故事板的 iOS 应用中有一个 UICollectionView.当设备处于纵向时,我希望它垂直滚动,而当它在 Landscaper 中时,我希望它水平滚动.

I have a UICollectionView in my storyboard based iOS app. When the device is in the portrait orientation I'd like it to scroll vertically, and when it's in Landscaper I'd like it to scroll horizontally.

在 UICollectionView 我可以看到 scrollEnabled 成员,但我看不到设置滚动方向的方法.我错过了什么吗?

In UICollectionView I can see the scrollEnabled member, but I can see no way to set the scroll direction. Have I missed something?

推荐答案

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];

<小时>

还要注意,在流布局中的 prepareForLayout 中调用它似乎没问题...


Note too that it seems to be fine to call this in prepareForLayout in your flow layout...

@interface LayoutHorizontalThings : UICollectionViewFlowLayout
@end

@implementation LayoutHorizontalBooks
-(void)prepareLayout
    {
    [super prepareLayout];

    self.scrollDirection = UICollectionViewScrollDirectionHorizontal;

    self.minimumInteritemSpacing = 0;
    self.minimumLineSpacing = 0;
    self.itemSize = CGSizeMake(110,130);
    self.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    }

这篇关于如何更改 UICollectionView 中的滚动方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆