一个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];
}
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) {
}];
});
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。