๊ธ€ ์ž‘์„ฑ์ž: ์ด์ง€์›๐ŸŒฉ๏ธ

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)
}

์ขŒ์ธก: iOS 14.0, ์šฐ์ธก: iOS 13.0

๋!

 

์ฐธ๊ณ  ์ž๋ฃŒ

๋ฐ˜์‘ํ˜•