UIRefreshControl停止旋转

UIRefreshControl停止旋转

本文介绍了使应用程序处于非活动状态后,UIRefreshControl停止旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UITableView中使用UIRefreshControl:

I use UIRefreshControl in a UITableView:

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refresh)
         forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;

带有刷新处理程序:

-(void)refresh {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // (...some long running operation...)
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.refreshControl endRefreshing];
        });
    });
}

在长时间运行的操作中,我按下Home按钮使应用程序处于非活动状态。之后,我再次使该应用程序处于活动状态。旋转器冻结(停止旋转),无法将其恢复到初始状态。

During the long running operation I make the application inactive pressing Home button. After that I make the application active again. The spinner freezes (stops spinning) and there is no way to return it to the initial state.

如何解决?

推荐答案

我认为答案有点延迟,但是,今天我在ios 7上看到了类似的问题,ios 6继续旋转,

I think it is a bit delayed answer but , today I saw similar issue on ios 7 , ios 6 continued spinning ,

这里有一些解决方法

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if(self.refreshControl.isRefreshing) {
        CGPoint offset = self.tableView.contentOffset;
        [self.refreshControl endRefreshing];
        [self.refreshControl beginRefreshing];
        self.tableView.contentOffset = offset;
    }
}

它将停止并再次开始旋转,但仅发生在ios7上,所以也许我应该在ios6上不要这么做

it will stop and start again spinning , but it only happened on ios7 with me , so maybe you should check not to do it on ios6

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if(self.refreshControl.isRefreshing && [[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        CGPoint offset = self.tableView.contentOffset;
        [self.refreshControl endRefreshing];
        [self.refreshControl beginRefreshing];
        self.tableView.contentOffset = offset;
    }
}

这篇关于使应用程序处于非活动状态后,UIRefreshControl停止旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:38