present 新增 modalPresentationStyle
.pageSheet
.fromSheet
iOS 13
中 UIModalPresentationStyle
会默认为 .automatic
,而.automatic
大部分时间以.pageSheet
形式展现
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
你自己所创建的vc时,即.pageSheet
。 系统的UIImagePickerController
则在选择照片时会为.pageSheet
,而拍照时为.fullScreen
表现形式:
iPhone中会一层一层往上推出,后面做一个scale
image.png
iPad上不会覆盖全屏,而是居中的一个视图,继续present的话,会在中间一直叠加,如图:
image.png
当modalPresentationStyle
为.pageSheet
时候,系统会为界面添加一个下拉返回的功能,如果一些界面不需要,那么如何禁掉该功能?
我们需要把新界面的isModalInPresentation
设置为true
即可。这是我们也能下拉拖拽,但只能拖拽一小部分距离。
当然我们还可以在用户下拉的时候,来一个弹框询问用户是否真的要返回上级界面。那么界面需要遵循这个协议UIAdaptivePresentationControllerDelegate
,该协议在iOS13
中新增了两个方法
func draftDidChange()
// 这个方法中我们可以弹框进行提醒,这个方法仅在isModalInPresentation为true的时候会触发
func presentationControllerDidAttemptToDismiss(_: UIPresentationController)
image.png
UISearchController
Apple终于将UISearchbar
中的UISearchTextField
暴露为公共参数
Search Token
image.pnglet 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新特性
- 两个手指滑动即可触发多选
- iPad上如果有外接键盘,支持按着
shift
或command
的情况下,单击cell进行选择,和Mac
一样的操作。
UITableView
和UICollectionView
中新增两个方法来实现上述操作
optional func tableView(_ tableView: UITableView, shouldBeginMultipleSelectionInteractionAtIndexPath indexPath: IndexPath) -> Bool
optional func tableView(_ tableView: UITableView, didBeginMultipleSelectionInteractionAtIndexPath indexPath: IndexPath)
UIContextMenuInteraction
image.png效果如上图,看起来很像
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
吧。
创建该类对象相关代码如下:
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?
网友评论