开发者社区> 问答> 正文

UIRefreshControl加到UIScrollView上下拉刷新,出现跳跃

一个UIViewController 的- (void)viewDidLoad中初始化了一个UIScrollView在它上面加一个UIRefreshControl,实现下拉刷新。下拉刷新的过程中ScrollView会出现跳跃。谁知道这是为什么?(请回答中不要告诉我可以采用其他方法如EGO,我就是想知道为什么,谢谢大神)
下面是viewDidLoad的代码。

 - (void)viewDidLoad
      {
       [super viewDidLoad];
       UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    [scrollView setBackgroundColor:[UIColor whiteColor]];
    [scrollView setContentSize:CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    scrollView.alwaysBounceVertical = YES;
    [self.view addSubview:scrollView];
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, -200, scrollView.bounds.size.width, 200)];
    [topView setBackgroundColor:[UIColor brownColor]];
    [scrollView addSubview:topView];
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(testRefresh:) forControlEvents:UIControlEventValueChanged];

    [scrollView addSubview:refreshControl];
    [self.view addSubview:scrollView];
    }

展开
收起
a123456678 2016-07-27 15:36:10 2058 0
1 条回答
写回答
取消 提交回答
  • dispatch_async(dispatch_get_main_queue(), ^{
                [UIView animateWithDuration:kAnimationDuration animations:^{
                    self.scrollView.contentInset = inset;
                    [self.scrollView setContentOffset:CGPointMake(0, -inset.top) animated:NO];
                } completion:^(BOOL finished) {
                }];
            });
    2019-07-17 20:00:42
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载