จุดหยุดและตัวบ่งชี้การลาก
ปรับขนาดชีตด้วยจุดหยุดการนำเสนอ
จุดหยุดและตัวบ่งชี้การลาก เป็นบทเรียน SwiftUI Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน SwiftUI Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส SwiftUI Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
What Are Detents?
A detent is a stopping height a sheet can rest at, like half-open or full. They let users resize the sheet by dragging it. 📏
The presentationDetents Modifier
Add presentationDetents inside the sheet content to list the heights it can snap to. Pass a set of detents to enable resizing.
.presentationDetents([.medium, .large])Medium and Large
The two built-in detents are .medium, about half the screen, and .large, nearly full height. Offer both so users pick what fits.
.presentationDetents([.medium, .large])A Fixed Height Detent
Use .height to pin a sheet to an exact point size. This is great for short forms that should not grow taller than needed.
.presentationDetents([.height(220)])A Fraction Detent
The .fraction detent sizes the sheet to a share of the screen, like a third. It adapts nicely across different device sizes.
.presentationDetents([.fraction(0.33)])The Drag Indicator
The little grabber bar at the top is the drag indicator. It hints that the sheet can be pulled up, down, or dismissed.
Showing the Grabber
Add presentationDragIndicator set to .visible to always show the grabber, even when only one detent is available.
.presentationDragIndicator(.visible)Combining Modifiers
Detents and the drag indicator stack together on the sheet content. Apply both for a resizable sheet with a clear grab handle. ✨
ContentView()
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)Tracking the Selected Detent
Bind presentationDetents to a state value to know which height the user chose, so your layout can react to the current size.
.presentationDetents([.medium, .large], selection: $detent)Why Detents Matter
Detents keep sheets non-blocking. A medium sheet lets users glance at content while still seeing the screen behind it.
One Detent, No Resize
If you pass a single detent, the sheet stays one fixed height and cannot be resized, though it can still be swiped to dismiss.
.presentationDetents([.medium])Quick Check
Which modifier lets a sheet snap to multiple heights?
Recap: Detents
You can now resize sheets with detents like .medium, .large, and .fraction, plus show a grabber with the drag indicator. Great progress! 🎉
เรียนรู้ Swift ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 30
- บทเรียน
- 120
คำถามที่พบบ่อย
บทเรียน “จุดหยุดและตัวบ่งชี้การลาก” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “จุดหยุดและตัวบ่งชี้การลาก” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส SwiftUI Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส SwiftUI Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “จุดหยุดและตัวบ่งชี้การลาก”
ปรับขนาดชีตด้วยจุดหยุดการนำเสนอ คุณปฏิบัติ SwiftUI Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน SwiftUI Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน SwiftUI Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “จุดหยุดและตัวบ่งชี้การลาก” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน SwiftUI Academy นี้ได้ไหม
ได้ บทเรียน SwiftUI Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การแสดงชีต
- จุดหยุดและตัวบ่งชี้การลาก
- การแจ้งเตือนพร้อมการดำเนินการ
- กล่องโต้ตอบยืนยัน