present 新增 modalPresentationStyle
.pageSheet .fromSheet
iOS 13中 UIModalPresentationStyle 會默認為 .automatic,而.automatic大部分時間以.pageSheet形式展現(xiàn)
For most view controllers, UIKit maps this style to the UIModalPresentationStyle.pageSheet style, but some system view controllers may map to a different style.
而當present你自己所創(chuàng)建的vc時,即.pageSheet。 系統(tǒng)的UIImagePickerController則在選擇照片時會為.pageSheet,而拍照時為.fullScreen
表現(xiàn)形式:
iPhone中會一層一層往上推出,后面做一個scale

iPad上不會覆蓋全屏,而是居中的一個視圖,繼續(xù)present的話,會在中間一直疊加,如圖:

當modalPresentationStyle為.pageSheet時候,系統(tǒng)會為界面添加一個下拉返回的功能,如果一些界面不需要,那么如何禁掉該功能?
我們需要把新界面的isModalInPresentation設置為true即可。這是我們也能下拉拖拽,但只能拖拽一小部分距離。
當然我們還可以在用戶下拉的時候,來一個彈框詢問用戶是否真的要返回上級界面。那么界面需要遵循這個協(xié)議UIAdaptivePresentationControllerDelegate,該協(xié)議在iOS13中新增了兩個方法
func draftDidChange()
// 這個方法中我們可以彈框進行提醒,這個方法僅在isModalInPresentation為true的時候會觸發(fā)
func presentationControllerDidAttemptToDismiss(_: UIPresentationController)

UISearchController
Apple終于將UISearchbar中的UISearchTextField暴露為公共參數(shù)
Search Token

let selectedText = field.textIn(field.selectedTextRange) // "beach"
let token = UISearchToken(icon: nil, text: selectedText)
field.replaceTextualPortion(of: field.selectedTextRange, with: token, at: field.tokens.count)
UITableView和UICollectionview新特性
- 兩個手指滑動即可觸發(fā)多選
- iPad上如果有外接鍵盤,支持按著
shift或command的情況下,單擊cell進行選擇,和Mac一樣的操作。
UITableView和UICollectionView中新增兩個方法來實現(xiàn)上述操作
optional func tableView(_ tableView: UITableView, shouldBeginMultipleSelectionInteractionAtIndexPath indexPath: IndexPath) -> Bool
optional func tableView(_ tableView: UITableView, didBeginMultipleSelectionInteractionAtIndexPath indexPath: IndexPath)
UIContextMenuInteraction

效果如上圖,看起來很像
3D Touch的 Peek And Pop,官方給出的解釋
this sounds a lot like Peek and Pop in some ways. Well, we noticed that too.
However, since this new API provides a much larger feature set and works on multiple platforms, we are deprecating UIViewController previewing in iOS 13.
So, go and replace your implementation of Peek and Pop with UIContextMenuInteraction and give your users a consistent experience in your app across all devices.
所以。。。放棄3D Touch吧。
創(chuàng)建該類對象相關代碼如下:
let actionProvider = (suggestedActions: [UIMenuElement]) -> UIMenu? {
let editMenu = UIMenu(title: "Edit...", children: [
UIAction(title: "Copy") { ... },
UIAction(title: "Duplicate") { ... }
])
return UIMenu(children: [
UIAction(title: "Share") { ... },
editMenu,
UIAction(title: "Delete", style: .destructive) { ... }
])
}.
return UIContextMenuConfiguration(identifier: "unique-ID" as NSCopying, previewProvider: nil, actionProvider: actionProvider)
UITableView也做了相應的支持,在UITableViewDelegate中添加了如下方法
optional func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAtIndexPath indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration?