Offsetting UIRefreshControl

2019-02-02 22:14发布

I am currently using a JASidePanel for my application and I have a UITableViewcontroller with a UIRefreshControl as one of the ViewControllers for it. The width of my tableview still has a width of 320 pixels so the UIRefreshControl gets centered right in the middle of the view. I'm trying to figure out if there's a way to offset the UIRefreshControl (moving the x by 20 pixels to the left) so that it looks centered when I have my side panel visible.

Thanks! JASidePanel

7条回答
劳资没心,怎么记你
2楼-- · 2019-02-02 23:09

UIRefreshControl's frame is automatically managed so trying to change it's position will likely yield in unexpected results (especially between iOS SDK versions). As you've noted, the control is always centered horizontally in it's superview's frame. Knowing this you can 'take advantage' of the situation by offsetting your superview.

In your case, set your table view's frame to CGRect(-40, 0, 360, superViewHight). This will cause your table view to sit 40 points to the left of the window. So you will need to adjust your table view's content accordingly so that it sits 40 points to the right or just extends an extra 40 points, but the stuff rendering off screen should be padding.

Once you do this your UIRefreshControl will sit 20 points to the left as you desire due to the fact that it is centered.

enter image description here

查看更多
登录 后发表回答