ios – iCarousel拉动刷新并加载更多

ios – iCarousel拉动刷新并加载更多,第1张

概述我成功地能够集成iCarousel组件,但现在面临一个问题,以实现“拉动刷新”和& “加载更多”功能. 实际上iCarousel是UIView的子类,而“Pull to Refresh”& “加载更多”功能通常适用于UIScrollView的子类. UIView不支持这些功能.因此,我陷入了困境. 我不知道如何实现“Pull to Refresh”& UIView(ICarousel)的“加载更多 我成功地能够集成iCarousel组件,但现在面临一个问题,以实现“拉动刷新”和& “加载更多”功能.

实际上iCarousel是UIVIEw的子类,而“Pull to Refresh”& “加载更多”功能通常适用于UIScrollVIEw的子类. UIVIEw不支持这些功能.因此,我陷入了困境.

我不知道如何实现“Pull to Refresh”& UIVIEw(ICarousel)的“加载更多”功能?

解决方法 解

您可以使用scrollOffset属性和carouselDIDScroll方法来实现“Pull to Refresh”& “加载更多”功能.

@property (nonatomic,assign) CGfloat scrollOffset;

This is the current scroll offset of the carousel in multiples of the itemWIDth. This value,rounded to the nearest integer,is the currentItemIndex value. You can use this value to position other screen elements while the carousel is in motion. The value can also be set if you wish to scroll the carousel to a particular offset programmatically. This may be useful if you wish to disable the built-in gesture handling and provIDe your own implementation.

- (voID)carouselDIDScroll:(iCarousel *)carousel;

This method is called whenever the carousel is scrolled. It is called regardless of whether the carousel was scrolled programmatically or through user interaction.

在这里有一些你需要知道的要点.

> scrollOffset< 0:用户试图拉动刷新.
> scrollOffset> numberOfItems – 2:将显示最后一项

在carouselDIDScroll方法上实现此逻辑以存档功能.

- (voID)carouselDIDScroll:(iCarousel *)carousel {  // Start new pull request when user pulls |carousel|   // a distance equal to 0.4 wIDth/height of an item  if (carousel.scrollOffset < -0.4) {    [self pullToRefresh];  }  // Start new load more request when last item will be displayed.  // In this situation,I ignore cases when |numberOfItems| is small  // Ex: |numberOfItems| < 2  if (carousel.scrollOffset > carousel.numberOfItems - 2) {    [self loadMore];  }}- (voID)pullToRefresh {  // Make sure have only one request at a time  if (self.isPullingToRefresh) {    return;  }  self.isPullingToRefresh = YES;  // Request API to receive new data  // Update |isPullingToRefresh| when request finishes  self.isPullingToRefresh = NO;}- (voID)loadMore {  // Make sure have only one request at a time  if (self.isLoadingMore) {    return;  }  self.isLoadingMore = YES;  // Request API to receive new data  // Update |isLoadingMore| when request finishes  self.isLoadingMore = NO;}

结果

 

有关更多详细信息,您可以查看我的示例

https://github.com/trungducc/stackoverflow/tree/icarousel-pull-to-refresh-load-more

总结

以上是内存溢出为你收集整理的ios – iCarousel拉动刷新并加载更多全部内容,希望文章能够帮你解决ios – iCarousel拉动刷新并加载更多所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1073413.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存