Ios 创建完全自定义的UIRefresh控件

Ios 创建完全自定义的UIRefresh控件,ios,objective-c,uirefreshcontrol,Ios,Objective C,Uirefreshcontrol,我需要创建一个完全自定义的UIRefresh控件。动画、图像、下拉量等 我最初的想法是从头开始,使用UIViewController,向其中添加我自己的视图,通过访问UIScrollViewDelegate方法来设置动画 我可以做所有这些,但是有没有一种方法可以稍微少一些工作,并且更容易添加到多个UITableViews 是否可以将UIRefreshControl子类化并更改其中的内容量?EGOTableViewPullRefresh是一个很棒的“下拉刷新”功能。可从以下网址获得:。您可以自定义

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

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

我可以做所有这些,但是有没有一种方法可以稍微少一些工作,并且更容易添加到多个
UITableView
s


是否可以将UIRefreshControl子类化并更改其中的内容量?

EGOTableViewPullRefresh
是一个很棒的“下拉刷新”功能。可从以下网址获得:。您可以自定义您的图片、行为等。
UIRefreshControl
仅在iOS 6.0及更高版本中可用
EGOTableViewPullRefresh
可在iOS 5及更早版本中使用

EGOTableViewPullRefresh是一个很棒的“下拉刷新”功能。可从以下网址获得:。您可以自定义您的图片、行为等。
UIRefreshControl
仅在iOS 6.0及更高版本中可用
EGOTableViewPullRefresh
可在iOS 5及更早版本中使用

我们有一个教程,其中包含Objective-C和Swift中的示例代码,用于实现自定义拉动刷新控件。你可以在这里找到它:

希望有帮助,如果你有任何问题,请告诉我


--Anthony

我们有一个教程,其中包含Objective-C和Swift中的示例代码,用于实现自定义拉刷新控件。你可以在这里找到它:

希望有帮助,如果你有任何问题,请告诉我


--安东尼

答案更新

  • Swift 3.1的项目更新
  • 将QuartzCode更新为版本 1.55.0(生成代码的更改)
  • 代码重构以使用新的refreshControl属性(现在也更“快速”)
  • 包括@Hanny的建议(如下)(谢谢!)

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

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

退房(GitHub)。 在其中,您将找到QuartzCode项目文件以及如何将其与
UITableView
集成的示例

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

/// 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()
}

干杯

答案更新

  • Swift 3.1的项目更新
  • 将QuartzCode更新为版本 1.55.0(生成代码的更改)
  • 代码重构以使用新的refreshControl属性(现在也更“快速”)
  • 包括@Hanny的建议(如下)(谢谢!)

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

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

退房(GitHub)。 在其中,您将找到QuartzCode项目文件以及如何将其与
UITableView
集成的示例

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

/// 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()
}

干杯

谢谢,看起来很像我自己要做的:)谢谢,看起来很像我自己要做的:)谢谢,我终于能让它工作了。非常少的代码,因为这都是关于获得正确的布局约束。谢谢,我最终能够让它工作。代码非常少,因为这一切都是为了获得正确的布局约束。我认为animate()最好放在刷新函数的开头。当我们滚动数据时,没有必要设置动画。@汉尼,非常感谢你的评论。我同意。我对代码做了一些修改,并加入了您的建议。看一看我认为animate()最好放在刷新函数的开头。当我们滚动数据时,没有必要设置动画。@汉尼,非常感谢你的评论。我同意。我对代码做了一些修改,并加入了您的建议。看一看