gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 23:00:46 25 4
gpt4 key购买 nike

我已经成功地集成了 iCarousel 组件,但现在在实现“拉动刷新”和“加载更多”功能时遇到了问题。

实际上 iCarousel 是 UIView 的子类,而“拉动刷新”和“加载更多”功能通常与 UIScrollView 的子类一起使用。而 UIView 不支持这些功能。因此,我被困在这一点上。

我不知道如何使用 UIView(ICarousel) 实现“拉动刷新”和“加载更多”功能?

最佳答案

解决方案

您可以使用 scrollOffset属性(property)和carouselDidScroll实现“拉动刷新”和“加载更多”功能的方法。

@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 拉动刷新并加载更多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50153407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com