i have my refreshcontroller with a scrollview ..
I’m adding as a subview to a scrollView . It’s working when the page content is overflowing the screen. but the issue arise when i haven’t received much data and it’s not overflowing , the pull and refresh function is not working. 🙁
I’m not using tableview .
Can anybody help me how to solve this problem?
4 Answers 4
var alwaysBounceVertical: Bool // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag vertically
alwaysBounceVertical is not entirely true, and refreshControl has been introduced:
- All iOS versions: bounces is always required if contentSize is smaller than frame
- Pre iOS 10 versions: alwaysBounceVertical is also required for small content
- iOS 10+: notify the UIScrollView of the existence of a UIRefreshControl using refreshControl
— iOS 10
UIRefreshControl is now supported by UIScrollView , using refreshControl just like UITableView in previous OS.
This means that the drag & pull down experience, is flawless, without drift.
Follow the tap + drag on the white arrow in the animation below: they stay in sync
— iOS 9 and earlier
You can add a UIRefreshControl manually to a UIScrollView , but that view has no awareness of such an element, and the pull to refresh tends to drift.
Notice how much harder it is to pull to refresh on the animation below: scrolling of the white arrow drifts, and requires a much greater distance to trigger the control
Bypass refreshControl OS discrepancies with this scroll view extension :
I am building an RSS reader using swift and need to implement pull to reload functionality.
Here is how i am trying to do it.
Property ‘self.refresh’ not initialized at super.init call
Please help me to understand the behaviour of Gesture recognisers. A working sample code will be a great help.
17 Answers 17
Pull to refresh is built in iOS. You could do this in swift like
At some point you could end refreshing.
A Solution with storyboard and swift.
1.) Open your .storyboard file, select a TableViewController in your storyboard and "Enable" the Table View Controller — Refreshing feature in the Utilities.
2.) Open the associated UITableViewController-Class and add the following line into the viewDidLoad-Method.
Edited for Swift 5.0 :
OR in Swift 2.2:
3.) Add the following Method above the viewDidLoad-Method
iOS 10 — Swift 3 (Also applicable for iOS 11 — Swift 4)
I would like to mention a PRETTY COOL feature that has been included since iOS 10, which is:
For now, UIRefreshControl is directly supported in each of UICollectionView , UITableView and UIScrollView !
Each one of these views have refreshControl instance property, which means that there is no longer a need to add it as a subview in your scroll view, all you have to do is:
Personally, I find it more natural to treat it as a property for scroll view more than add it as a subview, especially because the only appropriate view to be as a superview for a UIRefreshControl is a scrollview, i.e the functionality of using UIRefreshControl is only useful when working with a scroll view; That’s why this approach should be more obvious to setup the refresh control view.
However, you still have the option of using the addSubview based on the iOS version:
ESPullToRefresh is an easy-to-use component that give pull-to-refresh and infinite-scrolling implemention for developers. By extension to UIScrollView, you can easily add pull-to-refresh and infinite-scrolling for any subclass of UIScrollView. If you want to customize its UI style, you just need conform the specified protocol.
- Xcode 8 or later
- iOS 8.0 or later
- Swift 2.3 or later
- Support UIScrollView and its subclasses UICollectionView UITableView UITextView
- Pull-Down to refresh and Pull-Up to load more
- Support customize your own style(s)
Download and run the ESPullToRefreshExample project in Xcode to see ESPullToRefresh in action.
Add ESPullToRefresh to your project
Add default pull-to-refresh
Add default infinite-scrolling
PS: Load effect is from MeiTuan iOS app.
Customize refresh need conform the ESRefreshProtocol and ESRefreshAnimatorProtocol protocol.
Add customize pull-to-refresh
Add customize infinite-scrolling
Espried and auto refresh
ESPullToRefresh support for the latest expiration time and the cache refresh time, You need set an refreshIdentifier to your UIScrollView.
You can use es.autoPullToRefresh() method, when the time over the last refresh interval expires automatically refreshed.
You are welcome to contribute to the project by forking the repo, modifying the code and opening issues or pull requests.
The MIT License (MIT)
Copyright (c) 2013-2016 eggswift
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.