Implement a horizontal UIRefreshControl

2019-04-13 21:02发布

问题:

How do I go and implement a UIRefreshControl which would get refreshed when pulled from left or right side??

Is it possible with the standard UIRefreshControl? Or is there any API to create this effect? I have been searching a lot to get some lead on this but I am not able to find anything.

All I could find is this answer on SO, but it is written in C# which I am not much familiar with.

回答1:

You could use a UITableViewController that is rotated 90 degrees.

Add [self.view setTransform:CGAffineTransformMakeRotation(-M_PI / 2)]; in the UITableViewController class during setup.

Example using UITableView (and not 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!



回答2:

There are no default refreshcontrol for this. You have to create custom refreshcontrol to get this behaviour.