LoginSignup
9
9

More than 1 year has passed since last update.

WWDC 2021: What's New in UIKit メモ

Posted at

Productivity

iPad multitasking

UIWindowScene.ActivationConfiguration(userActivity: userActivity) で、「新しいウインドウで開く」 コマンドを作成できる。

let newSceneAction = UIWindowScene.ActivationAction({ _ in
    // Create the user activity that represents the new scene content
    let userActivity = NSUserActivity(activityType: "com.myapp.detailscene")

    // Return the activation configuration
    return UIWindowScene.ActivationConfiguration(userActivity: userActivity)
})

Keyboard navigation

iPadOS 15

  • Band Selection = 複数項目をドラッグで一気に選択できる。

Keyboard shortcuts

iPadOS 15
UIMenuBuilderを使って、キーボードのショートカットを作成する。

class AppDelegate: UIResponder, UIApplicationDelegate {
    override func buildMenu(with builder: UIMenuBuilder) {
        // Use the builder to modify the main menu...
    }
}
  • iPadと、Mac Catalyst の UIFocusSystemが強化
  • アプリ間のドラッグアンドドロップが、iOS 15でiPhoneも可能に

iPad pointer

Screen Shot 2021-06-23 at 12.03.25.png

UI refinements

Bar背景の変更

UIToolbarとUITabbarで、下までスクロールした時、背景が無しになる

Screen Shot 2021-06-22 at 21.35.40.png

下までスクロールした時の外観は、scrollEdgeAppearanceでカスタマイズできる。

// Custom scrollEdgeAppearance
let appearance = UITabBarAppearance()
appearance.backgroundEffect = nil
appearance.backgroundColor = .blue
tabBar.scrollEdgeAppearance = appearance

// Specify the content scrollView
let scrollView = ... // Content scroll view in your app
viewController.setContentScrollView(scrollView, for: .bottom)

ヘッダーの変更

Screen Shot 2021-06-22 at 21.48.21.png

UIListContentConfiguration : iOS 14
UIListSeparatorConfiguration : iOS 14.5

半分の高さのシート

API enhancements

10:16

UIButtonの拡張

  • UIButtonConfiguration で外観の変更ができる。
    • Plain, Gray, Tinted ...
    • Pop-up, Pull-down, Toggle
// Configurationを使ってボタン作成
var config = UIButton.Configuration.tinted()
config.title = "Add to Cart"
config.image = UIImage(systemName: "cart.badge.plus")
config.imagePlacement = .trailing
config.buttonSize = .large
config.cornerStyle = .capsule
let button = UIButton(configuration: config)
  • UIContextMenuInteraction で、折りたたみ可能なサブメニューをサポート。APIの追加はないけど、以前は、サブメニューをタップすると置き換えされていたのが、展開されるようになった。

SF Symbols

  • Monochrome, Hierarchical, Palette, Multicolor の色が使えるようようになった (UIKit, SwiftUI, AppKit) Screen Shot 2021-06-23 at 10.13.09.png
  • UIImageSymbolConfiguration
let configuration = UIImage.SymbolConfiguration(
    hierarchicalColor: UIColor.systemOrange
)
let image = UIImage(
    systemName: "sun.max.circle.fill",
    withConfiguration: configuration
)
  • .circle, .circle.fill がAPIで利用できる

Dynamic Typeのサイズ制限

最小限サイズ、最大サイズの設定ができる。

extension UIView {
    var minimumContentSizeCategory: UIContentSizeCategory
    var maximumContentSizeCategory: UIContentSizeCategory
}

カラー

  • システムカラーが、全てのプラットフォームで統一
  • UIColor.tintColor を追加。 動的な色。
  • iOS 14.5で、 UIColorPickerの didSelectコールバックを追加

TextKit2

UISceneの状態を復元

  • NSUserActivityを使って、状態を復元できる
  • ここのウィンドウ制御関連は、UISceneベースのAPIで対応しているので、古いUIApplicationベースのアプリは、UISceneに移行してね

Cell configuration closures

  • UICollectionView, UITableViewのセルのConfigurationの更新をクロージャーで設定できる。 UIButtonにもあるよ。
// New UICollectionViewCell.configurationUpdateHandler closures
let cell: UICollectionViewCell = ...

cell.configurationUpdateHandler = { cell, state in
    var content = UIListContentConfiguration.cell().updated(for: state)
    content.text = "Hello world!"
    if state.isDisabled {
        content.textProperties.color = .systemGray
    }
    cell.contentConfiguration = content
}

Data Source差分の改良

  • 既存のセルをすべて破棄することなく、その変更内容に基づいてUIが更新
var snapshot = dataSource.snapshot()
snapshot.reconfigureItems(itemIdentifiers)
dataSource.apply(snapshot, animatingDifferences: false)

Performance

20:17

Cellプリフェッチの改良

  • iOS 15でビルドすると自動的に有効に
  • CellでImageをロードする場合は、awaitでasyncにしてみてね
  • UIImage.prepareThumbnailで適切な小さな画像にしてね

Security and privacy

Location Button

  • 現在地の取得を、一度だけ許可できるボタン

ペースト時のポップアップ

  • iOS 14から、他アプリからペーストした時に、画面上部に「** pasted from **」というポップアップが出るが、新しく追加された、標準的な貼り付けメニュー項目APIを使えば、表示されない。

Private Click Measurement

  • iOS 14.5 で導入
  • 広告のクリックやタップのプライバシーを保護した測定

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9