Open Taehyeon-Kim opened 2 years ago
iOS 15์์๋ Sheet์ ์ฌ๋ฌ ์ปค์คํ ์ต์ ์ ์ถ๊ฐํ ์ ์์ต๋๋ค.
Sheet ์ธ์คํด์ค๋ฅผ ์์ฑํฉ๋๋ค. UIPresentationController์ ์๋ธ ํด๋์ค์ธ UISheetPresentationController๋ฅผ ์ด์ฉํฉ๋๋ค. ์ํธ๋ก ๋์ฐ๊ณ ์ถ์ ์ธ์คํด์ค์ sheetPresentationController๋ฅผ ํธ์ถํฉ๋๋ค.
let viewControllerToPresent = UIViewController()
if let sheet = viewControllerToPresent.sheetPresentationController {
// customize
}
present(viewController, animated: true)
2๊ฐ์ง์ detents๊ฐ ์กด์ฌํฉ๋๋ค.
Array๋ก ๊ฐ๋จํ๊ฒ ์ค์ ํ ์ ์์ต๋๋ค.
sheet.detents = [.large()]
sheet.detents = [.medium(), .large()] // resizable ๊ฐ๋ฅํ ์ํ๊ฐ ๋ฉ๋๋ค.
sheet.detents = [.medium()] // full height์ผ๋ก resizable ๋์ง ์์ต๋๋ค.
iOS 16๋ถํฐ๋ ๋์ด๋ฅผ ์ปค์คํฐ๋ง์ด์ง ํ ์ ์์ต๋๋ค.
if let sheet = viewController.sheetPresentationController {
sheet.detents = [
.custom { _ in
return 200
}
]
}
if let sheet = viewController.sheetPresentationController {
sheet.detents = [
.custom { _ in
return 200
},
.custom { context in
return context.maximumDetentValue * 0.6
}
]
}
Present image picker in a standard sheet
func showImagePicker() {
let picker = PHPickerViewController()
picker.delegate = self
if let sheet = picker.sheetPresentationController {
sheet.detents = [.medium(), .large()]
}
present(picker, animated: true)
}
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
dismiss(animated: true)
}
๋ด๋ถ ์ปจํ ์ธ ๋ฅผ ์คํฌ๋กคํ๋ฉด ๊ฐ์ด ๋ฐ๋ผ์ฌ๋ผ๊ฐ๋ ๋ฌธ์
largestUndimmedDetentIdentifier
์ํธ ์๊ณผ ์ํธ ๋ค์์ ๋์์ ์ฝํ ์ธ ์ ์ํธ ์์ฉํ ์ ์๋๋ก ์ฑ์์ ๋น๋ชจ๋ฌ ํ๊ฒฝ์ ๊ตฌ์ถํ ์ ์์ต๋๋ค.
sheet.largestUndimmedDetentIdentifier = .medium // Defualt: nil
dimmed view๋ฅผ ์ ๊ฑฐํ๊ณ , delegate๋ฅผ ์ด์ฉํ๋ฉด ์ปค์คํฐ๋ง์ด์ฆํ ์ํธ ์์ฉ์ด ๊ฐ๋ฅํฉ๋๋ค.
sheet.prefersEdgeAttachedInCompactHeight = true
sheet.prefersGrabberVisible = true
sheet.preferredCornerRadius = 20
iPad์์ ์ํธ ๋์ ํ์ค๋ฒ๊ฐ ํ์ํ ๊ฒฝ์ฐ์๋ modal์ presentation style์ popover๋ก ์ค์ ํ๋ฉด ๋ฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ sheetPresentationController ๋์ popoverPresentationController์ ํธ์ถํฉ๋๋ค.