iOS: UIMenu ์ฌ์ฉํด๋ณด๊ธฐ

Apple์ ๋ฏธ๋ฆฌ ์๋ฆผ ์ฑ ํ๋ฉด์ด๋ค. ๋ด๋น๊ฒ์ด์
์ฐ์ธก ์๋จ ๋ฒํผ์ ํญ ํ๋ฉด ํด๋น ์์น์ ๋ฉ๋ด ๋ชฉ๋ก์ด ๋ํ๋๋ค. ์ง๊ธ ํ๊ณ ์๋ ํ๋ก์ ํธ์ ์ด ๋ฉ๋ด๋ฅผ ์ ์ฉํ๊ณ ์ถ์ด์ ์ฐพ์๋ดค๋๋ฐ, ActionSheet๋ฅผ ์ฌ์ฉํ๋ผ๋ ์๊ธฐ๊ฐ ๋ง์๋ค. ๊ทธ๋์ UIAlertController
๋ฅผ ์ฌ์ฉํ๋๋ฐ, ์ํ๋ ํ๋ฉด์ด ๋์ค์ง ์์๋ค. ์๊ณ ๋ณด๋, UIAlertController(.actionSheet)
๋ iPad์์๋ ์์ ๊ฐ์ด, ํญํ ์์น์ ํ์
? ๋ชจ๋ฌ? ํํ๋ก ๋์ค๊ณ , iOS์์๋ ๊ธฐ์กด์ ํํ ์๊ณ ์๋ ์ก์
์ํธ ํํ๋ก ๋์จ๋ค๋๋ผ. ์ ํ์์ ์คํํ์ง๋ ์์ ๊ธฐ๋ฅ์ ์ฐ์ง ์์ ํ
๋ฐ ๋ผ๋ ์๊ฐ์ ํด์ ๊ฐ๋ฐ์ ๋ฌธ์๋ฅผ ๋ค์ ์ฐพ์๋ณด๋, UIMenu
๋ผ๊ณ ๋ถ๋ฅธ๋ค๋ ๊ฒ์ ์์๋ค. ์ ..์ ๋ ์นด!
var menuItems: [UIAction] { return [ UIAction(title: I18N.modify, image: UIImage(systemName: "pencil"), handler: { _ in }), UIAction(title: I18N.delete, image: UIImage(systemName: "trash"), attributes: .destructive, handler: { _ in }) ] }
UIMenu
๋ ์ฌ๋ฌ ๊ฐ์ UIAction
์ ๊ฐ๊ณ ์๋ค. UIAlertController
๊ฐ UIAlertAction
์ ๊ฐ๊ณ ์๋ ๊ฒ๊ณผ ๋น์ทํ๋ค. handler
์๋ ํด๋น ๋ฉ๋ด ์์ดํ
์ ํญ ํ์ ๋ ์ด๋ ํ ๋์์ ์ฒ๋ฆฌํ ๊ฒ์ธ์ง ์์ฑํ๋ฉด ๋๋๋ฐ, ๋น ๊ฐ์ด๋ผ๋ ๋ฌด์กฐ๊ฑด ์จ์ผ ํ๋ค. handler: nil
์ด๋ ์์ handler
๋ฅผ ์ง์๋ดค๋๋ฐ, ์ค๋ฅ๊ฐ ๋ฌ๋ค.
UIMenu
๋ UIKeyCommand
๋ ๊ฐ์ง ์ ์๋๋ฐ, ์ด๋ macOS, iPadOS์์ ํค๋ณด๋๋ฅผ ์ฌ์ฉํ ๋ ๋จ์ถํค๋ก ์ ๊ทผํ ์ ์๊ฒ ํ๋ ์ปดํฌ๋ํธ๋ค.
var menu: UIMenu { return UIMenu(title: "", image: nil, identifier: nil, options: [], children: menuItems) }
์ด๋ ๊ฒ UIAction
๋ชฉ๋ก์ ๋ง๋ค๊ณ ๋์, UIMenu
์ ๋ด์์ฃผ์. ๋งจ ์ฒ์ ์ฐธ๊ณ ํ๋ ๋ฌธ์ฌ๋ ์์ ์ฝ๋์ฒ๋ผ ์ฐ์ฐ ํ๋กํผํฐ๋ก ์์ฑํ๋๋ฐ, Apple ๋ฌธ์๋ฅผ ๋ณด๋ฉด ๊ตณ์ด ์ฐ์ฐ ํ๋กํผํฐ๋ก ์์ฑํ์ง ์์๋ ๋๋ ๊ฑฐ ๊ฐ๋ค.
๋ฏธ๋ฆฌ ์๋ฆผ ์ฑ์ฒ๋ผ ๋ด๋น๊ฒ์ด์
๋ฐ ์์ดํ
์ผ๋ก ๋์ํ๊ฒ ํ๊ณ ์ถ์ผ๋ฉด, UIMenu
๋ฅผ UIBarButtonItem
์ ๋ด์์ navigationItem.rightBarButtonItem
์ผ๋ก ๋ฃ์ด์ฃผ๋ฉด ๋๋ค.
์์ฝ๊ฒ๋ UIMenu
๋ iOS 14.0 ๋ฒ์ ์ด์๋ถํฐ ์ง์ํ๋ค. ๊ทธ๋์ ๋๋ ๋ถ๊ธฐ๋ฅผ ๋๋ ์, iOS 14.0 ๋ฒ์ ์ดํ๋ฉด UIAlertController(.actionSheet)
๋ฅผ ๋ณด์ฌ์ฃผ๊ธฐ๋ก ํ๋ค.
if #available(iOS 14.0, *) { self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "", image: UIImage(systemName: "ellipsis.circle"), primaryAction: nil, menu: menu) } else { self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "ellipsis.circle"), style: .plain, target: self, action: #selector(moreActionTapped)) }
@objc func moreActionTapped(_ sender: UIBarButtonItem) { let alert = UIAlertController(title: nil, message: I18N.actionsheetMessage, preferredStyle: .actionSheet) let deleteAction = UIAlertAction(title: I18N.modify, style: .default, handler: { _ in }) let saveAction = UIAlertAction(title: I18N.delete, style: .destructive, handler: { _ in }) let cancelAction = UIAlertAction(title: I18N.cancle, style: .cancel, handler: { _ in }) alert.addAction(deleteAction) alert.addAction(saveAction) alert.addAction(cancelAction) self.present(alert, animated: true, completion: nil) }


๋!
์ฐธ๊ณ ์๋ฃ
- How to show UIMenu from UIButton or UIBarButtonItem
- Adding Menus and Shortcuts to the Menu Bar and User Interface
- UIMenu - Apple Developer Documentation
๋๊ธ
์ด ๊ธ ๊ณต์ ํ๊ธฐ
-
๊ตฌ๋
ํ๊ธฐ
๊ตฌ๋ ํ๊ธฐ
-
์นด์นด์คํก
์นด์นด์คํก
-
๋ผ์ธ
๋ผ์ธ
-
ํธ์ํฐ
ํธ์ํฐ
-
Facebook
Facebook
-
์นด์นด์ค์คํ ๋ฆฌ
์นด์นด์ค์คํ ๋ฆฌ
-
๋ฐด๋
๋ฐด๋
-
๋ค์ด๋ฒ ๋ธ๋ก๊ทธ
๋ค์ด๋ฒ ๋ธ๋ก๊ทธ
-
Pocket
Pocket
-
Evernote
Evernote
๋๊ธ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.