Article source address :medium.com/swlh/10-cod…
By Francesco Marisaldi
Translation: Liaoworking
WWDC2020 brings us a lot of new features and exciting announcements. Here are 10 code snippets that will be supported in the next iOS release. No more than five lines each.
1.SKOverlay
The first of the SKOverlay official documents allows us to display a floating layer in other apps to quickly download applications. You can set the location and the proxy, and you can listen for the appearance, disappearance and handling of the corresponding error through the proxy.
guard let scene = view.window? .windowScene else { return } let config = SKOverlay.AppConfiguration(appIdentifier: "your-app-id", position: .bottom) let overlay = SKOverlay(configuration: config) overlay.present(in: scene)Copy the code
The difference between it and SKStoreProductViewController is that it is just a floating layer rather than the full screen display. Designed for App Clips. Use SKOverlay. AppClipConfiguration set response to app and location, as shown in figure below.
2.Configurations
Configurations is a new API for setting views and Cell styles. It’s flexible because it can be used on any UIView, including collectionView and tableView cells, so it’s easy to use. Here is a UIListContentConfiguration examples of use:
var config = UIListContentConfiguration.subtitleCell()
config.image = UIImage(systemName:"tortoise")
config.text = "Hello world!"
config.secondaryText = "WWDC20"
let list = UIListContentView(configuration: config)
Copy the code
The List Content setting has many default Settings, including status, content, and background Settings. In addition, it replaces the UITableViewCell’s deprecated “textLabel”,”detailTextLabel”,”imageView” properties, and the specific document
3. Lists added to CollectionView
Starting with iOS 14, collectionView can be set to a tableView-like list style (which means the era of tableView is coming to an end), as shown in the following code:
let config = UICollectionLayoutListConfiguration(appearance: .insetGrouped)
let layout = UICollectionViewCompositionalLayout.list(using: config)
Copy the code
Lists will have different styles, and there will be sliding gestures, splitlines, accessories, and Lists in UICollectionView for WWDC to tell you more details.
4. Changes in positioning accuracy.
The Core Location framework is also getting some changes this time around. Allows users to choose the high or low accuracy of the location to share with the app. What if you need high precision reading and users share low precision? You can solve your problem with the following code:
let manager = CLLocationManager()
manager.requestTemporaryFullAccuracyAuthorization(withPurposeKey: "YOUR-PURPOSE-KEY") { (error) in
// Your code
}
Copy the code
Temporary high precision can only to the running process, you must pass on the info. Add NSLocationTemporaryUsageDescriptionDictionarykey plist and the corresponding description. If there are more requirements, or if you are interested, there are two sessions in WWDC: What’s New in Location and Design for Location Privacy.
5. Authorization for behavior tracking
Apple has put a lot of emphasis on user privacy this year. Not only location and browser, but also application data will be limited. If you have access to the device’s IDFA or other sensitive information to track user behavior. You now need to use the new AppTrackingTrasparency framework.
ATTrackingManager.requestTrackingAuthorization { (status) in
// your code
}
// To know current status
ATTrackingManager.trackingAuthorizationStatus
Copy the code
Need you in the info. To add in the plist NSUserTrackingUsageDescription key and the corresponding authorization. Users can set the authorization dialog box does not pop up. In this way, the authorization box of all apps on the phone will not pop up. Build Trust Through Better Privacy this session covers more details.
6. Initialize UIControls to have event callbacks
UIcontrols can now pass events through closures, eliminating the need for previous selectors to bind methods. As follows:
let action = UIAction(title: "") { _ in print("Tapped!" ) } let button = UIButton(frame: .zero, primaryAction: action)Copy the code
UIBarButtonItem triggers the menu bar
UIBarButtonItem now triggers the display menu bar. Apple’s user interaction guide recommends using this approach more often. Use the following code
let newFolder = UIAction(title: "New Folder", image: UIImage(systemName: "folder.badge.plus")) { _ in print("NewFolder")}
let edit = UIAction(title: "Edit", image: UIImage(systemName: "pencil.circle")) { _ in print("Edit") }
let menu = UIMenu(title: "", children: [newFolder, edit])
navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "ellipsis.circle"), menu: menu)
Copy the code
8. UIColorPickerViewController color selector
Similar to the image selector, the proxy method includes colorPickerViewControllerDidFinish and colorPickerViewControllerDidSelectColor (_) (_)
Use as follows:
let colorPicker = UIColorPickerViewController()
colorPicker.delegate = self
colorPicker.selectedColor = .orange
present(colorPicker, animated: true, completion: nil)
Copy the code
9.UIPageControl and UIDatePicker new API
Page indicators can be set with images as page indicators. Date picker has a new UI with pop-up menu display and.inline style
let pageControl = UIPageControl()
pageControl.preferredIndicatorImage = UIImage(systemName:"tortoise")
pageControl.setIndicatorImage(UIImage(systemName:"hare"), forPage:2)
let datePicker = UIDatePicker(frame: .zero)
datePicker.preferredDatePickerStyle = .inline
Copy the code
10. Added userInterface diom for Mac
The equipment before judging UIDevice. Current. Only when userInterfaceIdiom. IPhone,. The two options, new added in xcode12. MAC options There is no doubt more friendly to multiterminal development.