如何在app进入前台之前准备UI更新

Pei*_*Pei 13 user-interface animation ios

我知道Apple不推荐在后台使用App时更新UI,特别是对于OpenGL.

但是,我刚刚意识到iMessenger和Facebook的使者看起来能够做到这一点.与您的朋友一起输入消息主题,然后转到后台,然后在应用程序仍在后台时收到新消息,然后将此应用程序带到前台(单击推送通知或应用程序图标),您会发现新消息气泡是已经存在图标中的应用扩展动画.

根据我的理解,这只会发生,因为新的消息气泡已经在后台模式下绘制.然后当app进入前景时,它可以出现在动画中.

但是根据我的测试结果,在iOS8和iOS9中,所有后台UI更新都将在应用程序生效后推迟.此外,iOS将为该UI更新添加隐式动画事务.

我列出了我的测试代码,如下所示,当应用程序进入前台时,你会看到新的单元格被添加到表格中,显示动画事务,完全不同于iMessenger.tableView:numberOfRowsInSection:仅在app进入前台时执行延迟.

并且不仅对于tableview单元更新,即使在后台添加子视图也将触发用于输入前景的类似延迟事务.

也许我对这方面的方向完全错误.有谁能帮我理解iMessenger和FB的使者如何能够达到这种效果?提前致谢!

@interface ViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic) UITableView *tableView;
@property (nonatomic) NSMutableArray *dataTable;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
  [self.view addSubview:self.tableView];
  self.tableView.delegate = self;
  self.tableView.dataSource = self;
  [self.tableView registerClass:[UITableViewCell class]
         forCellReuseIdentifier:@"kCellId"];

  self.dataTable = [[NSMutableArray alloc] initWithArray:@[@"1", @"2", @"3"]];

  __weak __typeof(self) weakSelf = self;
  [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidEnterBackgroundNotification
                                                    object:nil
                                                     queue:[NSOperationQueue mainQueue]
                                                usingBlock:^(NSNotification * _Nonnull note) {
                                                  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)),
                                                                 dispatch_get_main_queue(), ^{
                                                    [weakSelf.dataTable addObject:[@(weakSelf.dataTable.count + 1) stringValue]];
                                                    [weakSelf.tableView reloadData];
                                                  });
                                                }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  return self.dataTable.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"kCellId"];
  cell.textLabel.text = self.dataTable[indexPath.row];
  return cell;
}

@end
Run Code Online (Sandbox Code Playgroud)

Ram*_*mis 1

我建议您查看launch-mageAPN 负载文档

\n\n

launch-image - 应用程序包中图像文件的文件名;它可能包含扩展名或省略它。当用户点击操作按钮或移动操作滑块时,该图像将用作启动图像。如果未指定此属性,系统要么使用以前的快照,要么使用 app\xe2\x80\x99s Info.plist 文件中的 UILaunchImageFile 键标识的图像,或者回退到 Default.png。\n已添加此属性在iOS 4.0中。

\n