- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我的应用程序中已经有大约 5 个 UIScrollView
,它们都加载多个 .xib
文件。我们现在要使用 UIRefreshControl
。它们被构建为与 UITableViewControllers 一起使用(根据 UIRefreshControl 类引用)。我不想重做所有 5 个 UIScrollView
的工作方式。我已经尝试在我的 UIScrollView
中使用 UIRefreshControl
,除少数情况外,它按预期工作。
刷新图片进入加载器后,UIScrollView
向下跳了大约 10 个像素,只有当我非常小心地拖动 UIScrollview
非常缓慢地下降。
当我向下滚动并启动重新加载,然后放开
UIScrollView
时,UIScrollView
会停留在我放开的位置。重新加载完成后,UIScrollView
跳到顶部,没有动画。
这是我的代码:
-(void)viewDidLoad
{
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
[myScrollView addSubview:refreshControl];
}
-(void)handleRefresh:(UIRefreshControl *)refresh {
// Reload my data
[refresh endRefreshing];
}
有什么方法可以节省大量时间并在 UIScrollView
中使用 UIRefreshControl
?
谢谢!!!
最佳答案
我有一个 UIRefreshControl
来与 UIScrollView
一起工作:
- (void)viewDidLoad
{
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
scrollView.userInteractionEnabled = TRUE;
scrollView.scrollEnabled = TRUE;
scrollView.backgroundColor = [UIColor whiteColor];
scrollView.contentSize = CGSizeMake(500, 1000);
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(testRefresh:) forControlEvents:UIControlEventValueChanged];
[scrollView addSubview:refreshControl];
[self.view addSubview:scrollView];
}
- (void)testRefresh:(UIRefreshControl *)refreshControl
{
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing data..."];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[NSThread sleepForTimeInterval:3];//for 3 seconds, prevent scrollview from bouncing back down (which would cover up the refresh view immediately and stop the user from even seeing the refresh text / animation)
dispatch_async(dispatch_get_main_queue(), ^{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM d, h:mm a"];
NSString *lastUpdate = [NSString stringWithFormat:@"Last updated on %@", [formatter stringFromDate:[NSDate date]]];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:lastUpdate];
[refreshControl endRefreshing];
NSLog(@"refresh end");
});
});
}
需要在单独的线程上进行数据更新,否则会锁定主线程(UI 用于更新 UI)。因此,当主线程忙于更新数据时,UI 也被锁定或卡住,您永远看不到流畅的动画或微调器。
编辑:好的,我正在做与 OP 相同的事情,我现在向它添加了一些文本(即“拉动刷新”),它确实需要回到主线程来更新该文本.
更新的答案。
关于ios - 我可以在 UIScrollView 中使用 UIRefreshControl 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14905382/
抱歉这个奇怪的标题,但是,这正是我所需要的。我知道这是可以做到的,因为我见过其他应用程序这样做。 基本上,我的应用程序有一个启用分页的大 ScrollView ,其中包含一些嵌套的 ScrollVie
我还没有尝试过,但我假设一旦我知道用户想要在子 ScrollView 中滚动,我就必须禁用父 ScrollView 的滚动,对吗? 两个 ScrollView 都是水平滚动的。 如何暂时禁用父级的滚动
我需要实现这个方法: - (CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center { 但我不知道如何获得我需要的中心坐标。通常
我想根据 UIAccelerometer 值滚动 ScrollView 。实现这一目标的最佳方法是什么? 最初,我根据获得的加速度计值将内容偏移设置为一个值。然后在每个 scrollViewDidEn
我有一个 UIScrollView,我需要底部淡入透明,这样它就不会突然切断内容。 UIScrollView 的背景是自定义颜色。这是我到目前为止所拥有的,但图层显示为白色,而不是自定义颜色。这就是我
我有一个 UIScrollviews 彼此存在的层次结构。 如何将特定区域的滑动事件重定向到内部 ScrollView ? 最佳答案 如果您将 UIScrollViews 设置为只能在一个轴或另一轴上
在我的应用程序中,我有一个扩展 UIScrollView 并在用户滚动时填充其内容的 View 。但是,如果用户滚动太快,则 UIScrollView 内填充的 View 不会及时创建,您实际上可以看
我有一个包含内容的 UIScroll View 。如果该内容溢出,使 ScrollView 可滚动,我想将 View 的底部设置为某种颜色。如果没有,我想将其设置为不同的颜色。 我的问题是,我不知道如
我有一个 ScrollView ,其中包含一个 UIImageView,以及一个额外的 UIScrollView 和 UIImageView。 我想要实现的是独立缩放和平移每个 ScrollView
类似的问题也有人问过这个,但我的困境其实和他们正好相反。我有一个全屏、分页 UIScrollView,每个页面都是屏幕的大小。在其中,我有一些页面本身就是 UIScrollViews,它们的宽度大于屏
我有一个 UIScrollView 和另一个 UIScrollView 。它们都水平滚动并且具有 pagingEnabled = YES。假设我开始滚动内部 ScrollView 并到达最右边界。如果
我有一个 UIScrollView,里面有一个(自定义)UIView。 在我的 scrollViewDidScroll 方法中,我正在调用 [myCustomView setNeedsDisplay]
我有一个水平滚动的 UICollectionView,其中填充了垂直滚动的 UITableViews(两者都是 UISCrollView 的子类)。当滚动手势开始沿任一方向滚动时,在其减速完成之前不会
iOS 8, swift 。我试图在水平 ScrollView 上创建垂直 ScrollView 。它们都是 UIScrollView。垂直 ScrollView 允许从底部向上滑动 View 。顶部
我需要一个分页的 UIScrollView,它以 UIScreenEdgePanGestureRecognizer 的方式检测屏幕边缘的平移,而不是像 UIPanGestureRecognizer 那
假设我有多个 ScrollView ,并且我希望在任何给定时间只打开其中一个 (scrollView.contentOffset != 0)。因此,当 scroll view 1 打开且 scroll
我在分页 UIScrollView(外部)中的 VC 中有 UIScrollView(内部 - UICollectionView 是诚实的)。两者都是水平的。当我向内滚动到边缘(左侧或右侧)时,它开始
如何在不干扰现有 UIScrollView 的情况下从现有 UIScrollView 获取重复的 UIScrollView。 第一个 ScrollView , UIScrollView *firstS
我的应用程序中有一个点,我删除了一个 ScrollView 并添加了另一个。我希望新 ScrollView 中也能出现上一个 ScrollView 中的相同手势。我尝试过: s
请告诉我如何在类似嵌套进程的 ScrollView 中设置 ScrollView 。 以下代码部分有效。 int x=10; int y=10; for(int i=0; i<5; i++) {
我是一名优秀的程序员,十分优秀!