简体   繁体   English

带有UIRefreshControl问题的水平UICollectionView

[英]Horizontal UICollectionView with UIRefreshControl issue

I have horizontal UICollectionView with UIRefreshControl : 我有水平的UICollectionViewUIRefreshControl

self.refreshControlMain = [[UIRefreshControl alloc] init];
//self.refreshControlMain.tintColor = [UIColor grayColor];
[self.refreshControlMain addTarget:self action:@selector(refershControlAction) forControlEvents:UIControlEventValueChanged];
[self.collectionViewMain addSubview:self.refreshControlMain];           
self.collectionViewMain.alwaysBounceVertical = YES;
self.collectionViewMain.pagingEnabled = YES;
self.collectionViewMain.showsHorizontalScrollIndicator = NO;
self.collectionViewMain.scrollEnabled = NO; 
//Because user can't scroll horizontally (he needs to press next button)

But this code doesn't work, because I can't drag it vertically. 但是此代码无效,因为我无法垂直拖动它。 The only option I found is to set self.collectionViewMain.scrollEnabled = YES; 我发现的唯一选项是设置self.collectionViewMain.scrollEnabled = YES; (and in this case I can drag it vertically, so that refresh control appears), but in this case user is able to scroll horizontally (but user shouldn't be able to do that). (在这种情况下,我可以垂直拖动它,以便显示刷新控件),但是在这种情况下,用户可以水平滚动(但用户不应该这样做)。

Is there any option to use refresh control in my situation? 在我的情况下,可以使用刷新控制吗?

update: 更新:

I don't need horisontal refresh control. 我不需要水平刷新控制。 I have horisontal collectionview, but I need vertical refresh control. 我有水平collectionview,但是我需要垂直刷新控件。 if I put "self.collectionViewMain.scrollEnabled = YES" in my code, it works. 如果我在代码中输入“ self.collectionViewMain.scrollEnabled = YES”,则它可以正常工作。 but I need user not be able to scroll himself. 但我需要用户不能滚动自己。

UIRefreshControl does not support horizontal use natively. UIRefreshControl本身不支持水平使用。

There are various solutions whereby it has been extended for horizontal use. 有多种解决方案,可以将其扩展为水平使用。

Check out this link. 查看此链接。

Or as per this answer you could use a UITableViewController that is rotated 90 degrees. 或者按照此答案,您可以使用旋转90度的UITableViewController。

Add [self.view setTransform:CGAffineTransformMakeRotation(-M_PI / 2)]; 添加[self.view setTransform:CGAffineTransformMakeRotation(-M_PI / 2)]; in the UITableViewController class during setup. 在安装过程中在UITableViewController类中输入。

Example using UITableView (and not UITableViewController): 使用UITableView(而不是UITableViewController)的示例:

table_ = [[UITableView alloc] initWithFrame:self.bounds];
[table_ setDelegate:self];
[table_ setDataSource:self];
[table_ registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
[table_ setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];

UIRefreshControl *ctrl = [[UIRefreshControl alloc] init];
[ctrl setBackgroundColor:[UIColor yellowColor]];
[table_ addSubview:ctrl];

[self addSubview:table_];

Make sure to remember to rotate the content back again in the opposite direction! 请确保记住再次沿相反方向旋转内容!

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

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