UIRefreshControl 闪烁在 iOS7 中



如果 UIRefreshControl 以编程方式启动,(beginRefresh,然后结束刷新),当它不可见时,则在下次手动刷新时,UIRefreshControl 动画中将出现连续闪烁。

在UITableViewController子类中添加此方法,并在2秒后进行拉取以刷新,您将看到

闪烁
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    UIRefreshControl * refreshControl = [[UIRefreshControl alloc] init];
    self.refreshControl = refreshControl;
    [self.refreshControl beginRefreshing];
    double delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 
    (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [self.refreshControl endRefreshing];
    });
}

如何避免这种闪烁?

将代码放在 viewDidLoad 或 viewWillAppear 而不是 viewDidAppear 中。

另外,你能告诉我将代码放在viewDidAppear方法而不是viewDidLoad或viewWillAppear中的原因吗?

最新更新