LoginSignup
9
4

More than 3 years have passed since last update.

iOS13 beta6でContext Menusの仕様が変わったのかな?

Last updated at Posted at 2019-08-22

前提として以下のような画面遷移を作ろうとしています。
SS2019-08-23 5.27.03.png

iOS13で導入されたContext Menusを使ってプレビューを表示します。
プレビューをタップすると詳細画面に遷移します。

問題

正確に調べていないのでアレですが、
少なくともiOS13 beta6からプレビューをタップしても詳細画面に遷移しなくなりました。

原因

動いていた当時は

UITableViewDelegate
func tableView(_ tableView: UITableView, 
willCommitMenuWithAnimator animator: UIContextMenuInteractionCommitAnimating)

プレビューをタップするとこれが呼ばれていましたが、

少なくともiOS13 beta6からは

UITableViewDelegate
func tableView(_ tableView: UITableView, 
willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, 
animator: UIContextMenuInteractionCommitAnimating)

プレビューをタップするとこちらが呼ばれるようになりました。

Appleのドキュメントを見ても何も書いてありません。
久々に見たら書いてありました。

こちらのサイトを見るとiOS13 beta6でAPIが追加になってますね。
iOS13 Beta 5 to Beta6 API Differences

トリビア

プレビュー画面から画面遷移する処理は以下のようになりますが、

UITableViewDelegate
func tableView(_ tableView: UITableView, 
willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, 
animator: UIContextMenuInteractionCommitAnimating) {

    animator.addCompletion {
        // 画面遷移する処理
    }
}

上記処理にanimator.preferredCommitStyleを追加すると画面遷移するときの動きが選択できます。

// プレビュー画面から直接画面遷移する。(デフォルト)
animator.preferredCommitStyle = .pop
// 一度元の画面に戻ってから画面遷移する。
animator.preferredCommitStyle = .dismiss

Apple Developer Forumを見たところ、iOS13 beta6からの現象らしいので訂正します。

iOS13 beta8 + Xcode11 beta6に基づいて記述しています。
リリース版では変更される可能性があります。

9
4
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
4