简体   繁体   English

UILefreshControl在iOS7中闪烁

[英]UIRefreshControl flicker in iOS7

If UIRefreshControl is started programmatically,(beginRefreshing and then endRefreshing ) when it is not visible, then there would be a continuous flicker in the UIRefreshControl animation on next manual refresh. 如果UIRefreshControl以编程方式启动(beginRefreshing然后endRefreshing),当它不可见时,则在下次手动刷新时UIRefreshControl动画中会有连续的闪烁。

Add this method in UITableViewController subclass and do a pull to refresh after 2 seconds and you will see the flicker 在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];
    });
}

How to avoid this flicker? 如何避免这种闪烁?

Put your code in the viewDidLoad or viewWillAppear instead of viewDidAppear. 将代码放在viewDidLoad或viewWillAppear中,而不是viewDidAppear。

Also, can you tell me the reasoning behind putting the code inside the viewDidAppear method, rather than viewDidLoad or viewWillAppear? 另外,你能告诉我将代码放在viewDidAppear方法中的原因,而不是viewDidLoad或viewWillAppear吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM