UILefreshControl在iOS7中闪烁

时间:2013-10-23 14:48:34

标签: ios ios7 uitableview flicker uirefreshcontrol

如果UIRefreshControl以编程方式启动,(beginRefreshing然后endRefreshing)当它不可见时,则在下次手动刷新时UIRefreshControl动画中会有连续的闪烁。

在UITableViewController子类中添加此方法,并在2秒后执行pull刷新,您将看到闪烁

-(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];
    });
}

如何避免这种闪烁?

1 个答案:

答案 0 :(得分:0)

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

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