1

我需要创建一个完全自定义的UIRefresh控件。动画、图像、下拉量等...

我最初的想法是从头开始,使用 UIViewController,向其中添加我自己的视图,通过访问UIScrollViewDelegate方法来制作动画。

我可以做到这一切,但是有没有一种方法可以减少工作量并且更容易添加到多个UITableViews 中?

是否可以对其中的UIRefreshControl大量内容进行子类化和更改?

4

3 回答 3

3

答案已更新

  • GitHub项目更新到 Swift 3.1
  • 将 QuartzCode 更新到 1.55.0 版(生成代码的更改)
  • 重构代码以使用新refreshControl属性(在 iOS 10 中引入)(现在也更“迅速”)。
  • 包括@Hanny 的建议(在下方)(谢谢!)

我喜欢你发布的 YouTube 链接。:) 不错的结果。

供参考:QuartzCode 非常适合UIRefreshControl从头开始创建动画。

查看这个小项目(GitHub)。在其中,您将找到 QuartzCode 项目文件以及如何将其与UITableView.

我认为其中最重要的部分是refresh功能:

/// Called everytime refresh control's value changes.
///
/// - parameter sender: The `UIRefreshControl` of this TableView.
@IBAction func refresh(_ sender: UIRefreshControl) {

    animate()

    // In this "demo", the refresh will last 5.0 seconds.
    DispatchQueue.main.asyncAfter(deadline: .now() + 5) {

        // Do something with the retrieved data...
        // TODO

        // ... then end the refresh operation.
        self.refreshControl?.endRefreshing()

        // Stop animations.
        self.stopAnimations()
    }
}

看看使用动画是多么容易:

/// Three examples. Uncomment / comment to check all of them.
func animate() {

    // Example 01.
    animateCloudUpAndDown()

    // Example 02.
    //animateCloudStrokeWithGradientFill()

    // Example 03.
    //animateCloudStrokeWithSolidFill()
}

// MARK: - Animation Examples

/// Animates the cloud up and down.
func animateCloudUpAndDown() {
    customUIRefreshControl.addRefreshUpDownAnimation()
}

/// "Draws" the cloud by make its stroke line gradually visible, then shows
/// a solid blueish background and then fades everything out.
func animateCloudStrokeWithGradientFill() {
    customUIRefreshControl.addRefreshGradientAnimation()
}

/// "Draws" the cloud by make its stroke line gradually visible, then shows
/// a gradient blueish background and then fades everything out.
func animateCloudStrokeWithSolidFill() {
    customUIRefreshControl.addRefreshSolidAnimation()
}

干杯!

于 2016-05-11T12:09:10.547 回答
1

EGOTableViewPullRefresh is awesome "pull down to refresh" feature. It is available on github. You can customize your pics, behavior, etc. UIRefreshControl is available only in iOS 6.0 and later. EGOTableViewPullRefresh can be used in iOS 5 and earlier!

于 2013-07-17T13:09:34.613 回答
0

我们有一个教程,其中包含 Objective-C 和 Swift 中的示例代码,用于实现自定义拉取刷新控件。你可以在这里找到它:http ://www.jackrabbitmobile.com/design/ios-custom-pull-to-refresh-control/

希望对您有所帮助,如果您有任何问题,请告诉我!

——安东尼

于 2015-02-27T14:50:32.663 回答