iOS 13 WWDC Modernizing Your UI

2019-07-18  本文已影响0人  奴良

present 新增 modalPresentationStyle

.pageSheet .fromSheet
iOS 13UIModalPresentationStyle 会默认为 .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.png
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新特性

optional func tableView(_ tableView: UITableView, shouldBeginMultipleSelectionInteractionAtIndexPath indexPath: IndexPath) -> Bool

optional func tableView(_ tableView: UITableView, didBeginMultipleSelectionInteractionAtIndexPath indexPath: IndexPath)

UIContextMenuInteraction

image.png
效果如上图,看起来很像 3D TouchPeek 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?
上一篇 下一篇

猜你喜欢

热点阅读