wwdc2019
The week of online WWDC 2020 has unveiled big features and exciting announcements; among with important news, there’re many other notable additions coming with new SDKs. Here’s a list of 10 code snippets will be available with the next iOS’s major release: no more than 5 lines of code each. Let’s start 🧑🏼💻
在线WWDC 2020一周揭晓了重大功能并发布了令人兴奋的公告; 除了重要的新闻外,新的SDK还包含许多其他值得注意的功能。 以下是iOS的主要发行版中提供的10个代码段的列表:每行最多不超过5行代码。 让我们开始吧
1. SKOverlay (1. SKOverlay)
The first api enables us to display an overlay to recommend another app, allowing the user to download it immediately. You can configure the position and set a delegate, in order to respond to events such as appearance, dismissal and errors.
第一个api使我们能够显示叠加层以推荐另一个应用程序,从而允许用户立即下载它。 您可以配置位置并设置委托,以响应外观,解雇和错误等事件。
It differs from SKStoreProductViewController
because it’s tailored for apps and it’s an overlay rather than a full view. Using the dedicated configuration for clips, the SKOverlay.AppClipConfiguration
, you’re able to recommend the app clip’s corresponding app, as showed in demos about App Clips.
它与SKStoreProductViewController
不同,因为它是为应用程序量身定制的,并且是覆盖图而不是完整视图。 使用剪辑的专用配置SKOverlay.AppClipConfiguration
,您可以推荐应用剪辑的相应应用,如有关应用剪辑的演示中所示。
2.配置 (2. Configurations)
Configurations is a brand new api to specify content and appearance of views and cells. It’s very flexible, because it can be applied to any UIView, including collection and table view cells, and very simple to use at the same time. This is an example of using UIListContentConfiguration
:
配置是一种全新的api,用于指定视图和单元格的内容和外观。 它非常灵活,因为它可以应用于任何UIView(包括集合和表视图单元格),并且非常容易同时使用。 这是使用UIListContentConfiguration
的示例:
List content configuration comes with many default configurations. Configurations covers state, content and background specifications; in addition, it’s replacing deprecated tableview cell’s textLabel
, detailTextLabel
and imageView
attributes. Dive into the documentation to learn about all features and use cases.
列表内容配置附带许多默认配置。 配置涵盖状态,内容和背景规范; 此外,它取代已过时的tableview细胞的textLabel
, detailTextLabel
和imageView
属性。 深入文档以了解所有功能和用例。
3.集合视图中的列表 (3. Lists in Collection View)
Starting from iOS 14, collection views can now be configured with a list layout, which has a UITableView
like appearance (someone marked this as the end of table view’s era), the simple setup is:
从iOS 14开始,集合视图现在可以使用列表布局进行配置,该列表布局具有类似于UITableView
外观(有人将其标记为表视图时代的结束),简单的设置是:
Lists come with different styles and list cells with swipe gestures, separators, accessories: Lists in UICollectionView session covers much of these details.
列表具有不同的样式,列表单元具有滑动手势,分隔符和附件: UICollectionView会话中的列表涵盖了许多此类详细信息。
4.定位精度 (4. Location accuracy)
There’re many news about Core Location, included the new accuracy permission, which allows users to choose between full and reduced accuracy when they share their location with apps. What if you need the precise location for a particular feature of your app and the user shared only the approximate one? You’re able to ask for it by using:
关于核心位置的新闻很多,其中包括新的准确性权限,该权限允许用户在与应用共享位置时在完全精度和降低精度之间进行选择。 如果您需要为应用程序的特定功能提供精确位置并且用户仅共享近似位置该怎么办? 您可以使用以下方法提出要求:
The temporary accuracy lasts for the running session only; the key must be added in the NSLocationTemporaryUsageDescriptionDictionary
inside the app’s Info.plist and you can add as much keys as you need, to cover different use cases. If you’re interested, I suggest to watch What’s new in location and Design for location privacy sessions from WWDC20.
临时精度仅在运行的会话中持续; 该密钥必须添加到NSLocationTemporaryUsageDescriptionDictionary
在应用程序的Info.plist中,您可以根据需要添加任意数量的键,以涵盖不同的用例。 如果您有兴趣,我建议您观看WWDC20的位置和会话设计中的位置隐私会话。
5.追踪授权 (5. Tracking authorization)
This year focus on user’s privacy didn't cover only location and web browsing, but also data used by apps. If you access the user’s IDFA and other sensible data for tracking purpose, you’re now required to ask permission to users using the new AppTrackingTrasparency
framework:
今年关注用户的隐私不仅涵盖位置和网络浏览,还涵盖了应用程序使用的数据。 如果您出于跟踪目的访问用户的IDFA和其他敏感数据,则现在需要使用新的AppTrackingTrasparency
框架向用户请求权限:
You also need to specify the NSUserTrackingUsageDescription
key in the Info.plist. Users can even opt-out entirely from this request, meaning that alerts from any apps will not be fired: the Build trust through better privacy session shows more about this topic.
您还需要在Info.plist中指定NSUserTrackingUsageDescription
键。 用户甚至可以完全退出此请求,这意味着不会触发来自任何应用程序的警报: 通过更好的隐私会话建立信任关系可显示有关此主题的更多信息。
6.使用操作参数初始化UIControls (6. Init UIControls with an action parameter)
UIControls can now be instantiated with a handy primary action as parameter (no more selectors 🎉), like:
现在可以使用方便的主要操作作为参数来实例化UIControl(不再有选择器🎉),例如:
Same for UIBarButtonItem
or UISegmentedControl
(with an array of actions in this case); segmented controls get some other useful methods, like the ability to insert a segment with an action at a specified index.
与UIBarButtonItem
或UISegmentedControl
相同(在这种情况下具有一系列操作); 分段控件还有一些其他有用的方法,例如在指定索引处插入带有操作的分段的功能。
7.按钮上的菜单 (7. Menu from buttons)
Menus can now be shown from any buttons and the Human Interface Guidelines encourages this for many use cases: a good example is the “history menu” showed with a long tap on the back button in a navigation bar. Showing a UIMenu
from a button is really easy thanks to the new initializer:
现在可以从任何按钮显示菜单,《人机界面指南》在许多情况下都鼓励这样做:一个很好的例子是在导航栏中长按后退按钮即可显示“历史菜单”。 UIMenu
新的初始化UIMenu
从按钮显示UIMenu
真的很容易:
8. UIColorPickerViewController (8. UIColorPickerViewController)
Yes, an easy to use controller to manage the selection of a color from a UIColorWell
🎨 using colorPickerViewControllerDidFinish(_:)
and colorPickerViewControllerDidSelectColor(_:)
delegate’s methods:
是的,一个易于使用的控制器可以使用colorPickerViewControllerDidFinish colorPickerViewControllerDidFinish(_:)
和colorPickerViewControllerDidSelectColor(_:)
委托的方法来管理UIColorWell
a中的颜色选择:
9. UIPageControl和UIDatePicker的添加 (9. UIPageControl and UIDatePicker additions)
UIPageControl
has new nice features, included the ability to set images as custom page indicators. UIDatePicker
comes with a brand new UI, a pop-up menu and the new .inline
style:
UIPageControl
具有新的好功能,包括将图像设置为自定义页面指示符的功能。 UIDatePicker
带有全新的UI,弹出菜单和新的.inline
样式:
10. Mac成语 (10. Mac Idiom)
Thanks to the new mac
user interface idiom, it’s now more convenient to optimize UIs and behaviors for Catalyst apps (well, not only Catalyst apps, as any apps will potentially be able to run on Macs powered by Apple Silicon):
由于有了新的mac
用户界面习惯用法,现在可以更方便地优化Catalyst应用程序的UI和行为(不仅限于Catalyst应用程序,因为任何应用程序都可能可以在由Apple Silicon支持的Mac上运行):
if UIDevice.current.userInterfaceIdiom == .mac { //Your code }
And that's all! Hope you enjoyed Dub-Dub as me, we have big features and small improvements to dive in during next months; thanks for reading and catch up on the next article ☕️
就这样! 希望您喜欢我一样的Dub-Dub。 感谢您阅读并继续阅读下一篇文章☕️
翻译自: https://medium.com/swlh/10-code-snippets-from-wwdc20-5dba158e2903
wwdc2019