Drag and drop in SwiftUI
Generated on 8/3/2024
1 search
Drag and Drop in SwiftUI
Drag and drop functionality is a key feature in SwiftUI, and it is well-supported with accessibility technologies like VoiceOver and Voice Control. Here are some highlights from the sessions at WWDC 2024:
-
Accessibility in Drag and Drop:
- SwiftUI supports accessible drag and drop experiences using the
onDrag
andonDrop
modifiers. - You can enhance the drag and drop experience by defining multiple drop points on a single view, which can be accessed by VoiceOver.
- Example: An app that uses drag and drop to create custom alerts for friends when they comment. The app uses a custom drop delegate to support multiple drop points on a single view, making it accessible for VoiceOver users.
- Catch up on accessibility in SwiftUI (16:43)
- SwiftUI supports accessible drag and drop experiences using the
-
Drop Destinations on Tabs:
- Tabs in SwiftUI can be drop destinations, allowing for direct additions into tabs in the sidebar or tab bar through drag and drop.
- To support drop destinations on tabs in SwiftUI, use the
dropDestination
modifier on the tab with the receiver type. - Example: Adding a photo into a collection via drag and drop.
- Elevate your tab and sidebar experience in iPadOS (08:13)
-
Custom Drop Points:
- Define points on your view that can be dragged or dropped on, and provide labels that describe the interaction.
- Example: An app with three drop points for different sounds that can be set for an alert, making it accessible for VoiceOver.
- Catch up on accessibility in SwiftUI (17:30)
Relevant Sessions
These sessions provide comprehensive insights into implementing drag and drop in SwiftUI, especially focusing on accessibility and enhancing user experience.
Get started with HealthKit in visionOS
Discover how to use HealthKit to create experiences that take full advantage of the spatial canvas. Learn the capabilities of HealthKit on the platform, find out how to bring an existing iPadOS app to visionOS, and explore the special considerations governing HealthKit during a Guest User session. You’ll also learn ways to use SwiftUI, Swift Charts, and Swift concurrency to craft innovative experiences with HealthKit.
Migrate your TVML app to SwiftUI
SwiftUI helps you build great apps on all Apple platforms and is the preferred toolkit for bringing your content into the living room with tvOS 18. Learn how to use SwiftUI to create familiar layouts and controls from TVMLKit, and get tips and best practices.
SwiftUI essentials
Join us on a tour of SwiftUI, Apple’s declarative user interface framework. Learn essential concepts for building apps in SwiftUI, like views, state variables, and layout. Discover the breadth of APIs for building fully featured experiences and crafting unique custom components. Whether you’re brand new to SwiftUI or an experienced developer, you’ll learn how to take advantage of what SwiftUI has to offer when building great apps.
What’s new in SwiftUI
Learn how you can use SwiftUI to build great apps for any Apple platform. Explore a fresh new look and feel for tabs and documents on iPadOS. Improve your window management with new windowing APIs, and gain more control over immersive spaces and volumes in your visionOS apps. We’ll also take you through other exciting refinements that help you make expressive charts, customize and layout text, and so much more.
Catch up on accessibility in SwiftUI
SwiftUI makes it easy to build amazing experiences that are accessible to everyone. We’ll discover how assistive technologies understand and navigate your app through the rich accessibility elements provided by SwiftUI. We’ll also discuss how you can further customize these experiences by providing more information about your app’s content and interactions by using accessibility modifiers.
Elevate your tab and sidebar experience in iPadOS
iPadOS 18 introduces a new navigation system that gives people the flexibility to choose between using a tab bar or sidebar. The newly redesigned tab bar provides more space for content and other functionality. Learn how to use SwiftUI and UIKit to enable customization features – like adding, removing and reordering tabs – to enable a more personal touch in your app.