今天重绘时,扩展视图会闪烁 [英] Today Extension view flashes when redrawing

查看:118
本文介绍了今天重绘时,扩展视图会闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Apple文档,为了帮助您的窗口小部件查看最新版本,系统偶尔会捕获窗口小部件视图的快照。当窗口小部件再次可见时,将显示最新的快照,直到系统将其替换为实时版本视图。



然而,我所看到的是,在准备实时视图之前,快照将从屏幕上删除。这会产生闪光效果,其中旧快照从屏幕上取下,视图在一瞬间是空白,然后出现新视图。



开发人员是否负责快照和实时视图之间的过渡是否无缝?如果是这样,那背后的策略是什么?我没有看到任何直接控制转换的方法。



通过将数据加载到
widgetPerformUpdateWithCompletionHandler并保持绘图,我能够大大减轻这种影响。在viewWillAppear:中,但我仍然会在通知中心每隔15(左右)打开一次闪存。

解决方案

我有同样的问题,最后想出了我的小部件问题。事实证明,这与我对Widget生命周期的误解有关。



从文档中我认为今天的视图会保留我的快照小部件状态直到 widgetPerformUpdateWithCompletionHandler 方法完成处理程序成功调用。



这似乎不是这种情况。从我所看到的,快照仅在今日视图动画制作时使用(当用户拉下通知中心时)。一旦今天的视图被加载并且静止,你的小部件就会从头开始加载(如果使用则从xib中膨胀)并且调用 viewDidLoad 。此时,您应该使用缓存数据(而不是Web请求)填充窗口小部件。如果不这样,您将看到笔尖的临时数据。这是导致闪烁的原因。



viewDidLoad 完成时 widgetPerformUpdateWithCompletionHandler ,允许您获取新数据。获取新数据时,您应该调用完成处理程序并缓存数据,以便稍后从头开始加载窗口小部件时可以使用它(在 viewDidLoad 中)。 / p>

缓存数据的一种简单方法是用户默认值。


According to Apple documentation, "To help your widget look up to date, the system occasionally captures snapshots of your widget’s view. When the widget becomes visible again, the most recent snapshot is displayed until the system replaces it with a live version of the view."

What I am seeing, however, is that the snapshot is removed from screen before the live view is prepared. This results in a flash effect where the old snapshot is taken off screen, the view is blank for a split second, then the new view appears.

Is the developer responsible for making the transition between the snapshot and the live view seamless? If so, what is the strategy behind doing that? I don't see any way to directly control that transition.

I was able to mitigate the effect greatly by moving data loading to widgetPerformUpdateWithCompletionHandler: and keeping drawing in viewWillAppear:, but I do still see a flash once every 15 (or so) opens of the Notification Center.

解决方案

I had this same issue and finally figured out the issue I was having with my widget. It turns out it was related to a misunderstanding about the Widget Life Cycle on my behalf.

From the documentation I thought that the today view would keep a 'snapshot' of my widgets state until the widgetPerformUpdateWithCompletionHandler method completion handler was called with success.

This does not seem to be the case. From what I can see the 'snapshot' is just used when the Today View is animating in (when the user pulls down the notification centre). As soon as the today view is loaded and stationary your widget is loaded from scratch (inflated from xib if using) and viewDidLoad is called. At this moment you should populate you widget with cached data (not from a web request). If you don't you will see temporary data from your nib. This is what causes the flashing.

When viewDidLoad is complete widgetPerformUpdateWithCompletionHandler is called which allows you to fetch fresh data. When the fresh data is fetched you should call the completion handler and cache the data it so it can be used when the widget is loaded later on from scratch (in viewDidLoad).

A simple way to cache the data is in user defaults.

这篇关于今天重绘时,扩展视图会闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆