Secret-Of-SwiftUI / SSDC22

๐Ÿคก ์‘~ ์งˆ๋ ค? deprecated ํ•˜๋ฉด ๊ทธ๋งŒ์ด์•ผ~
9 stars 0 forks source link

Customize and resize sheets in UIKit #21

Open Taehyeon-Kim opened 2 years ago

Taehyeon-Kim commented 2 years ago

Discover how you can create a layered and customized sheet experience in UIKit. We'll explore how you can build a non-modal experience in your app to allow interaction with content both in a sheet and behind the sheet at the same time. We'll also take you through sheet size customization, revealing or hiding grabber controls, and adapting between popovers and customized sheets in your app. To get the most out of this session, we recommend watching the Presentations portion of โ€œModernizing Your UI for iOS 13โ€ from WWDC19 beginning at 9:45.

Taehyeon-Kim commented 2 years ago
c1

iOS 15์—์„œ๋Š” Sheet์— ์—ฌ๋Ÿฌ ์ปค์Šคํ…€ ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

c2

1. Getting a sheet

Sheet ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. UIPresentationController์˜ ์„œ๋ธŒ ํด๋ž˜์Šค์ธ UISheetPresentationController๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค. ์‹œํŠธ๋กœ ๋„์šฐ๊ณ  ์‹ถ์€ ์ธ์Šคํ„ด์Šค์— sheetPresentationController๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

let viewControllerToPresent = UIViewController()
if let sheet = viewControllerToPresent.sheetPresentationController {
  // customize
}
present(viewController, animated: true)

2. detents

2๊ฐ€์ง€์˜ detents๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

Array๋กœ ๊ฐ„๋‹จํ•˜๊ฒŒ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

sheet.detents = [.large()]
sheet.detents = [.medium(), .large()] // resizable ๊ฐ€๋Šฅํ•œ ์ƒํƒœ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
sheet.detents = [.medium()] // full height์œผ๋กœ resizable ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

c3

Whatโ€™s new in UIKit์„ ์ฐธ๊ณ ํ•˜์ž.

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

3. PickerViewController์— ์ ์šฉํ•˜๊ธฐ

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

4. prefersScrollingExpandWhenScrolledToEdge

๋‚ด๋ถ€ ์ปจํ…์ธ ๋ฅผ ์Šคํฌ๋กคํ•˜๋ฉด ๊ฐ™์ด ๋”ฐ๋ผ์˜ฌ๋ผ๊ฐ€๋Š” ๋ฌธ์ œ Simulator Screen Recording - iPhone 13 mini - 2022-07-31 at 18 50 50

5-1. Dimmed View ์ œ๊ฑฐ

largestUndimmedDetentIdentifier

์‹œํŠธ ์•ˆ๊ณผ ์‹œํŠธ ๋’ค์—์„œ ๋™์‹œ์— ์ฝ˜ํ…์ธ ์™€ ์ƒํ˜ธ ์ž‘์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์•ฑ์—์„œ ๋น„๋ชจ๋‹ฌ ํ™˜๊ฒฝ์„ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

sheet.largestUndimmedDetentIdentifier = .medium  // Defualt: nil

5-2. delegate์™€ ์—ฎ๊ธฐ

dimmed view๋ฅผ ์ œ๊ฑฐํ•˜๊ณ , delegate๋ฅผ ์ด์šฉํ•˜๋ฉด ์ปค์Šคํ„ฐ๋งˆ์ด์ฆˆํ•œ ์ƒํ˜ธ ์ž‘์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

c7

6. ๊ฐ€๋กœ๋ชจ๋“œ ์‹œ

sheet.prefersEdgeAttachedInCompactHeight = true
c6 c7

7. Grabber

sheet.prefersGrabberVisible = true
c8

8. CornerRadius

sheet.preferredCornerRadius = 20
c9

9. Adaptation from popover

iPad์—์„œ ์‹œํŠธ ๋Œ€์‹  ํŒ์˜ค๋ฒ„๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐ์—๋Š” modal์˜ presentation style์„ popover๋กœ ์„ค์ •ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  sheetPresentationController ๋Œ€์‹  popoverPresentationController์„ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

c10 c11