Search results for

“swiftui”

17,493 results found

Post

Replies

Boosts

Views

Activity

SwiftUI + SpriteKit interop: best practices for HUD overlays in a tile-based puzzle game?
Hey all, I'm building a tile-based puzzle game for iOS and have been experimenting with using SwiftUI for the HUD (score, timer, pause menu, settings sheet) layered on top of a SpriteView that hosts the actual gameplay scene. So far the integration has been smoother than I expected — SpriteView drops cleanly into a ZStack, and I can drive SwiftUI state from the SpriteKit scene via an ObservableObject shared between them. That said, I've run into a few rough edges that I'd love some input on. The biggest one is touch handling: when a SwiftUI overlay (like a semi-transparent pause button) sits over the SpriteView, taps near the edges of the button occasionally get swallowed by the underlying scene, even when the button's hit area looks correct in the view debugger. I've tried .contentShape(Rectangle()) and bumping the frame, which helps but doesn't fully eliminate it. Curious if anyone has landed on a reliable pattern here, especially for transient overlays like toast notifications th
0
0
1.2k
May ’26
SwiftUI NavigationSplitView sidebar toolbar has excessive top inset when embedded in TabView since iPadOS 26.4
I’m seeing a layout regression in SwiftUI on iPadOS 26.4 involving NavigationSplitView inside a TabView. When a NavigationSplitView is embedded in a TabView, the sidebar toolbar appears to reserve too much vertical space. There is a large vertical gap between the top edge of the sidebar and the sidebar collapse/toggle icon. It looks as if the sidebar toolbar itself has become much taller than expected. The same NavigationSplitView layout is rendered correctly when it is shown directly without being embedded in a TabView. Environment: iPadOS 26.4 or later SwiftUI iPad TabView NavigationSplitView inside one tab Expected behavior The sidebar toolbar should use its normal height, as it does when the same NavigationSplitView is shown without a surrounding TabView. The sidebar collapse/toggle icon should appear close to the top of the sidebar, without a large empty gap above it. Actual behavior When the NavigationSplitView is hosted inside a TabView, the sidebar toolbar area becomes excessively ta
3
0
745
May ’26
RealityView Camera Target Error when set while Orbiting
When interacting with RealityView’s realityViewCameraControls .orbit and setting a new RealityViewCameraContent .cameraTarget, the resulting camera target and camera orbit is incorrect. This can be demonstrated where one finger is orbiting the RealityView, and another pushes a button which changes the camera target. Instead of the camera facing the new target, some point in the scene is the new effective camera target and orbit point. This only occurs when an orbit interaction is currently taking place. If you stop interacting with the orbit, change target, then start orbit interacting again, everything works as expected. Though this example uses two-touches, any change of the camera target has this conflict with orbit interaction. This means interacting with orbit will result in the wrong camera view which is unexpected for users and difficult to reconcile or detect, for developers. Expected: Interacting (orbiting) the scene while setting a new camera target with the buttons on screen (at the same time), the
2
0
1.1k
May ’26
Reply to How can I intercept Shift+Tab in SwiftUI on macOS?
Hello @fahad-sh, I see what's going on here, At a system level, macOS is intercepting Shift+Tab before SwiftUI ever sees it. .onKeyPress is unable to capture this. Use NSEvent.addLocalMonitorForEvents with the following key and modifier. if event.keyCode == 48 && event.modifierFlags.contains(.shift) These three links cover everything needed: NSEvent > addLocalMonitorForEvents NSEvent > modifierFlags NSEvent > keycode ‎ struct ContentView: View { @State private var count = 0 var body: some View { Text(count) .onAppear { NSEvent.addLocalMonitorForEvents(matching: .keyDown) { event in if event.keyCode == 48 && event.modifierFlags.contains(.shift) { count += 1 return nil } return event } } } } ‎ I hope that helps!  Travis
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’26
Reply to ImageRenderer fails to render Text views that use @AccessibilityFocusState (.accessibilityFocused)
Thanks for your post and great description. There are many developers here that I’m sure they’ll jump into this thread. But what you see if a SwiftUI behavior. iOS 16, ok I don't think anything changed in the SwiftUI behavior. ImageRenderer generates its output entirely off-screen. Because the view is never attached to a live UIWindow, it lacks access to the active responder chain, the focus engine, and the accessibility tree. However, this is different as when SwiftUI encounters property wrappers that inherently rely on these live UIKit/AppKit bridges (like @AccessibilityFocusState and sometimes @FocusState), the view update cycle for that specific element silently fails or aborts, resulting in the view being dropped from the layout pass entirely. While you can inject standard SwiftUI environment values into an ImageRenderer (e.g., renderer.environment(.colorScheme, .dark)), you cannot inject a mock accessibility tree or a UIWindow context. The cleanest way to handle this
May ’26
ImageRenderer fails to render Text views that use @AccessibilityFocusState (.accessibilityFocused)
Environment: iOS 16.0+ SwiftUI Problem Description: I am using ImageRenderer to convert a SwiftUI view into a UIImage for sharing purposes. The view renders perfectly fine on-screen. However, in the generated UIImage, specific Text elements completely disappear. After debugging, I found that the issue is caused by the @AccessibilityFocusState property wrapper. Any Text view that has the .accessibilityFocused(_:) modifier applied to it will be completely missing from the ImageRenderer output. Other views (like Text without the modifier, or Image views) in the exact same hierarchy render perfectly. It seems that because ImageRenderer renders the view off-screen without a live accessibility environment/tree, the accessibility focus binding silently breaks the layout or rendering of that specific element. Minimal Reproducible Example: Here is a generic, drop-in example that demonstrates the bug. When you tap Capture with ImageRenderer, the resulting image will only contain the subtitle, while th
2
0
1.3k
May ’26
How can I intercept Shift+Tab in SwiftUI on macOS?
Hi everyone, I'm building a macOS SwiftUI app and I'm trying to intercept both: Tab Shift + Tab to perform custom actions (similar to how text editors indent/outdent items). Right now, plain Tab works fine, but Shift + Tab never reaches my .onKeyPress(.tab) handler. Here's what I'm currently trying: import SwiftUI struct ShiftTabNotIntercepted: View { @State private var shiftKeyPressed = false var body: some View { Text(Hello) .focusable() .onKeyPress(.tab) { print(tab pressed with shift: (shiftKeyPressed)) return .handled } .onModifierKeysChanged(mask: .shift) { old, new in shiftKeyPressed = new.contains(.shift) } } } Behavior: Pressing Tab prints: tab pressed with shift: false Pressing Shift + Tab does nothing — .onKeyPress(.tab) never fires. I also noticed: if a sidebar is visible, Shift + Tab moves focus to the sidebar if no sidebar is visible, it still doesn't trigger the handler So it seems macOS is intercepting Shift + Tab for focus navigation before SwiftUI sees it. My goal
1
0
392
May ’26
How to handle all the core AppleEvents
Glancing through the APIs, SwiftUI can handle the open app, reopen app, open doc, and quit core events (with the “aevt” suite ID). What about the print doc and open content events? If there are no hooks (yet), how can I implement them the traditional way without clashing with SwiftUI?
1
0
529
May ’26
iOS 18.6.2 issue with "let"
I am facing an issue in SwiftUI on iOS 18.6.2 where passing a value to a destination view during navigation is not working as expected. In my implementation, I pass a billerId as a constant (let) to the destination view (BillersItemView) using NavigationLink. This approach works correctly across all previous iOS versions. However, on iOS 18.6.2, the destination view does not receive the updated value properly. Before triggering navigation, the value is correctly updated in the ViewModel, but the destination view seems to receive an incorrect or stale value, which affects further API calls and UI rendering. This pattern of passing immutable (let) values is used throughout the app and has always worked reliably, so this behavior appears inconsistent and possibly related to changes in SwiftUI navigation handling in iOS 18.6.2. Could you please confirm if this is a known issue or if there are any recommended changes or workarounds to ensure correct data passing in this scenario? It can be very l
Topic: UI Frameworks SubTopic: SwiftUI
0
0
102
May ’26
Reply to How to achieve this vibrant background effect on iOS?
Thanks @darkpaw. Here is a simplified version of the code import SwiftUI struct DetailView: View { var body: some View { ZStack { GradientBackdrop() List { Section { LabeledValueRow( label: Company, value: ACME Inc. ) LabeledValueRow( label: Email, value: test@example.com ) Text(Schedule Appointment) Text(Add to Favorites) } .listRowBackground( Rectangle() .background(.thinMaterial) .colorScheme(.dark) ) .listRowSeparatorTint(.white.opacity(0.4)) .colorScheme(.dark) } .listSectionSpacing(.compact) .scrollContentBackground(.hidden) } } } #Preview { DetailView() } What I want to achieve is something like this, where the rows adapt to the underlying color
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’26
Reply to Tap to Pay Entitlement only for development
I have the same problem. My application ID indicates that the Tap to Pay on iPhone option is enabled on the Apple Developer Portal (this feature also appears in the Signature & Capabilities tab of Xcode), and the entitlement file is correctly provided in its project bundle. In development/debug mode, the functionality is available and operational: my application can perform Tap-to-Pay payment simulations via the Stripe PSP, using the Stripe Terminal SDK for SwiftUI. However, Xcode reports that the provisioning profile defined with this application ID for distribution on the App Store and loaded into Xcode does not include the com.apple.developer.proximity-reader.payment.acceptance authorization, even though all configuration settings comply with Apple's documentation guidelines. I've regenerated the profile several times without success (and when I use Automatically Manage Signing in Xcode, attempting to distribute an archive to Release Testing (TestFlight) generates an error message stating that
Topic: Code Signing SubTopic: Entitlements Tags:
May ’26
Reply to ToolbarItemGroup With Palette Style Cannot Present a View Controller While the Context Menu Is Visible
IFIRC I’ve had success working around this kind of issue by getting the transitionCoordinator and adding an empty animation alongside it and then presenting the view controller in the completion handler. Fallback and just present it if transition coordinator is nil. https://developer.apple.com/documentation/uikit/uiviewcontroller/transitioncoordinator?language=objc I don‘t SwiftUI though so Albert‘s answer might be the better one for your project
Topic: UI Frameworks SubTopic: UIKit Tags:
May ’26
XPC Communication between Editor app and user-compiled code
Hello! I'm trying to implement an editor app (macOS) that allows the user to write code, which will be compiled and executed, showing the result in the editor window. Imagine it like SwiftUI previews, but the graphic output is created with Metal, not SwiftUI. I found that IOSurface can be used to share that kind of data over XPC, so I would not have to rely on the private NSRemoteView. However, I'm confused if it is, at all, possible for my editor app to connect to an XPC Service, that was NOT bundled with it (but compiled by it at runtime). I succeeded to launch an XPC service defined as: Label com.myteam.myproject.service MachServices com.myteam.myproject.service Program /Path/to/service/run_my_service.sh But the call to let connection = NSXPCConnection(machServiceName: com.myteam.myproject.service) let proxy = connection.remoteObjectProxyWithErrorHandler { error in continuation.resume(throwing: error) } as? MyServiceProtocol fails with The connection to service named com.myteam.m
6
0
1.5k
May ’26
Reply to CLLocationManager permission prompt never appears in Swift Playground
Solved! Thank you to everyone who responded. The issue: The location permission prompt never appeared when requestWhenInUseAuthorization() was called from within a SwiftUI sheet (modal view). iOS silently ignores permission requests made from inside sheets. The fix: Move the permission request to the parent view’s .onAppear modifier — before any sheet is presented. The LocationManager is created as a @StateObject in the main ContentView, requestPermission() is called in ContentView.onAppear, and the LocationManager instance is passed into the sheet view as an @ObservedObject. Key points: • The Core Location When in Use capability must be enabled in Swift Playgrounds app settings • Use @StateObject in the parent view, @ObservedObject in the sheet • Call requestWhenInUseAuthorization() from the main view, not from inside a sheet • startUpdatingLocation() can still be called from within the sheet’s .onAppear Hope this helps someone else!
May ’26
SwiftUI + SpriteKit interop: best practices for HUD overlays in a tile-based puzzle game?
Hey all, I'm building a tile-based puzzle game for iOS and have been experimenting with using SwiftUI for the HUD (score, timer, pause menu, settings sheet) layered on top of a SpriteView that hosts the actual gameplay scene. So far the integration has been smoother than I expected — SpriteView drops cleanly into a ZStack, and I can drive SwiftUI state from the SpriteKit scene via an ObservableObject shared between them. That said, I've run into a few rough edges that I'd love some input on. The biggest one is touch handling: when a SwiftUI overlay (like a semi-transparent pause button) sits over the SpriteView, taps near the edges of the button occasionally get swallowed by the underlying scene, even when the button's hit area looks correct in the view debugger. I've tried .contentShape(Rectangle()) and bumping the frame, which helps but doesn't fully eliminate it. Curious if anyone has landed on a reliable pattern here, especially for transient overlays like toast notifications th
Replies
0
Boosts
0
Views
1.2k
Activity
May ’26
SwiftUI NavigationSplitView sidebar toolbar has excessive top inset when embedded in TabView since iPadOS 26.4
I’m seeing a layout regression in SwiftUI on iPadOS 26.4 involving NavigationSplitView inside a TabView. When a NavigationSplitView is embedded in a TabView, the sidebar toolbar appears to reserve too much vertical space. There is a large vertical gap between the top edge of the sidebar and the sidebar collapse/toggle icon. It looks as if the sidebar toolbar itself has become much taller than expected. The same NavigationSplitView layout is rendered correctly when it is shown directly without being embedded in a TabView. Environment: iPadOS 26.4 or later SwiftUI iPad TabView NavigationSplitView inside one tab Expected behavior The sidebar toolbar should use its normal height, as it does when the same NavigationSplitView is shown without a surrounding TabView. The sidebar collapse/toggle icon should appear close to the top of the sidebar, without a large empty gap above it. Actual behavior When the NavigationSplitView is hosted inside a TabView, the sidebar toolbar area becomes excessively ta
Replies
3
Boosts
0
Views
745
Activity
May ’26
RealityView Camera Target Error when set while Orbiting
When interacting with RealityView’s realityViewCameraControls .orbit and setting a new RealityViewCameraContent .cameraTarget, the resulting camera target and camera orbit is incorrect. This can be demonstrated where one finger is orbiting the RealityView, and another pushes a button which changes the camera target. Instead of the camera facing the new target, some point in the scene is the new effective camera target and orbit point. This only occurs when an orbit interaction is currently taking place. If you stop interacting with the orbit, change target, then start orbit interacting again, everything works as expected. Though this example uses two-touches, any change of the camera target has this conflict with orbit interaction. This means interacting with orbit will result in the wrong camera view which is unexpected for users and difficult to reconcile or detect, for developers. Expected: Interacting (orbiting) the scene while setting a new camera target with the buttons on screen (at the same time), the
Replies
2
Boosts
0
Views
1.1k
Activity
May ’26
Reply to How can I intercept Shift+Tab in SwiftUI on macOS?
Hello @fahad-sh, I see what's going on here, At a system level, macOS is intercepting Shift+Tab before SwiftUI ever sees it. .onKeyPress is unable to capture this. Use NSEvent.addLocalMonitorForEvents with the following key and modifier. if event.keyCode == 48 && event.modifierFlags.contains(.shift) These three links cover everything needed: NSEvent > addLocalMonitorForEvents NSEvent > modifierFlags NSEvent > keycode ‎ struct ContentView: View { @State private var count = 0 var body: some View { Text(count) .onAppear { NSEvent.addLocalMonitorForEvents(matching: .keyDown) { event in if event.keyCode == 48 && event.modifierFlags.contains(.shift) { count += 1 return nil } return event } } } } ‎ I hope that helps!  Travis
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’26
Reply to ImageRenderer fails to render Text views that use @AccessibilityFocusState (.accessibilityFocused)
Thanks for your post and great description. There are many developers here that I’m sure they’ll jump into this thread. But what you see if a SwiftUI behavior. iOS 16, ok I don't think anything changed in the SwiftUI behavior. ImageRenderer generates its output entirely off-screen. Because the view is never attached to a live UIWindow, it lacks access to the active responder chain, the focus engine, and the accessibility tree. However, this is different as when SwiftUI encounters property wrappers that inherently rely on these live UIKit/AppKit bridges (like @AccessibilityFocusState and sometimes @FocusState), the view update cycle for that specific element silently fails or aborts, resulting in the view being dropped from the layout pass entirely. While you can inject standard SwiftUI environment values into an ImageRenderer (e.g., renderer.environment(.colorScheme, .dark)), you cannot inject a mock accessibility tree or a UIWindow context. The cleanest way to handle this
Replies
Boosts
Views
Activity
May ’26
ImageRenderer fails to render Text views that use @AccessibilityFocusState (.accessibilityFocused)
Environment: iOS 16.0+ SwiftUI Problem Description: I am using ImageRenderer to convert a SwiftUI view into a UIImage for sharing purposes. The view renders perfectly fine on-screen. However, in the generated UIImage, specific Text elements completely disappear. After debugging, I found that the issue is caused by the @AccessibilityFocusState property wrapper. Any Text view that has the .accessibilityFocused(_:) modifier applied to it will be completely missing from the ImageRenderer output. Other views (like Text without the modifier, or Image views) in the exact same hierarchy render perfectly. It seems that because ImageRenderer renders the view off-screen without a live accessibility environment/tree, the accessibility focus binding silently breaks the layout or rendering of that specific element. Minimal Reproducible Example: Here is a generic, drop-in example that demonstrates the bug. When you tap Capture with ImageRenderer, the resulting image will only contain the subtitle, while th
Replies
2
Boosts
0
Views
1.3k
Activity
May ’26
How can I intercept Shift+Tab in SwiftUI on macOS?
Hi everyone, I'm building a macOS SwiftUI app and I'm trying to intercept both: Tab Shift + Tab to perform custom actions (similar to how text editors indent/outdent items). Right now, plain Tab works fine, but Shift + Tab never reaches my .onKeyPress(.tab) handler. Here's what I'm currently trying: import SwiftUI struct ShiftTabNotIntercepted: View { @State private var shiftKeyPressed = false var body: some View { Text(Hello) .focusable() .onKeyPress(.tab) { print(tab pressed with shift: (shiftKeyPressed)) return .handled } .onModifierKeysChanged(mask: .shift) { old, new in shiftKeyPressed = new.contains(.shift) } } } Behavior: Pressing Tab prints: tab pressed with shift: false Pressing Shift + Tab does nothing — .onKeyPress(.tab) never fires. I also noticed: if a sidebar is visible, Shift + Tab moves focus to the sidebar if no sidebar is visible, it still doesn't trigger the handler So it seems macOS is intercepting Shift + Tab for focus navigation before SwiftUI sees it. My goal
Replies
1
Boosts
0
Views
392
Activity
May ’26
Prominent glass button in SwiftUI incorrect text style
How do you create a prominent glass button in SwiftUI? In UIKit it’s let button = UIButton(configuration: .prominentGlass()) button.configuration?.title = Agree I tried Button(Agree) {} .buttonStyle(.glassProminent) but the title text is white not glassified 🤨
Replies
0
Boosts
0
Views
196
Activity
May ’26
How to handle all the core AppleEvents
Glancing through the APIs, SwiftUI can handle the open app, reopen app, open doc, and quit core events (with the “aevt” suite ID). What about the print doc and open content events? If there are no hooks (yet), how can I implement them the traditional way without clashing with SwiftUI?
Replies
1
Boosts
0
Views
529
Activity
May ’26
iOS 18.6.2 issue with "let"
I am facing an issue in SwiftUI on iOS 18.6.2 where passing a value to a destination view during navigation is not working as expected. In my implementation, I pass a billerId as a constant (let) to the destination view (BillersItemView) using NavigationLink. This approach works correctly across all previous iOS versions. However, on iOS 18.6.2, the destination view does not receive the updated value properly. Before triggering navigation, the value is correctly updated in the ViewModel, but the destination view seems to receive an incorrect or stale value, which affects further API calls and UI rendering. This pattern of passing immutable (let) values is used throughout the app and has always worked reliably, so this behavior appears inconsistent and possibly related to changes in SwiftUI navigation handling in iOS 18.6.2. Could you please confirm if this is a known issue or if there are any recommended changes or workarounds to ensure correct data passing in this scenario? It can be very l
Topic: UI Frameworks SubTopic: SwiftUI
Replies
0
Boosts
0
Views
102
Activity
May ’26
Reply to How to achieve this vibrant background effect on iOS?
Thanks @darkpaw. Here is a simplified version of the code import SwiftUI struct DetailView: View { var body: some View { ZStack { GradientBackdrop() List { Section { LabeledValueRow( label: Company, value: ACME Inc. ) LabeledValueRow( label: Email, value: test@example.com ) Text(Schedule Appointment) Text(Add to Favorites) } .listRowBackground( Rectangle() .background(.thinMaterial) .colorScheme(.dark) ) .listRowSeparatorTint(.white.opacity(0.4)) .colorScheme(.dark) } .listSectionSpacing(.compact) .scrollContentBackground(.hidden) } } } #Preview { DetailView() } What I want to achieve is something like this, where the rows adapt to the underlying color
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’26
Reply to Tap to Pay Entitlement only for development
I have the same problem. My application ID indicates that the Tap to Pay on iPhone option is enabled on the Apple Developer Portal (this feature also appears in the Signature & Capabilities tab of Xcode), and the entitlement file is correctly provided in its project bundle. In development/debug mode, the functionality is available and operational: my application can perform Tap-to-Pay payment simulations via the Stripe PSP, using the Stripe Terminal SDK for SwiftUI. However, Xcode reports that the provisioning profile defined with this application ID for distribution on the App Store and loaded into Xcode does not include the com.apple.developer.proximity-reader.payment.acceptance authorization, even though all configuration settings comply with Apple's documentation guidelines. I've regenerated the profile several times without success (and when I use Automatically Manage Signing in Xcode, attempting to distribute an archive to Release Testing (TestFlight) generates an error message stating that
Topic: Code Signing SubTopic: Entitlements Tags:
Replies
Boosts
Views
Activity
May ’26
Reply to ToolbarItemGroup With Palette Style Cannot Present a View Controller While the Context Menu Is Visible
IFIRC I’ve had success working around this kind of issue by getting the transitionCoordinator and adding an empty animation alongside it and then presenting the view controller in the completion handler. Fallback and just present it if transition coordinator is nil. https://developer.apple.com/documentation/uikit/uiviewcontroller/transitioncoordinator?language=objc I don‘t SwiftUI though so Albert‘s answer might be the better one for your project
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
May ’26
XPC Communication between Editor app and user-compiled code
Hello! I'm trying to implement an editor app (macOS) that allows the user to write code, which will be compiled and executed, showing the result in the editor window. Imagine it like SwiftUI previews, but the graphic output is created with Metal, not SwiftUI. I found that IOSurface can be used to share that kind of data over XPC, so I would not have to rely on the private NSRemoteView. However, I'm confused if it is, at all, possible for my editor app to connect to an XPC Service, that was NOT bundled with it (but compiled by it at runtime). I succeeded to launch an XPC service defined as: Label com.myteam.myproject.service MachServices com.myteam.myproject.service Program /Path/to/service/run_my_service.sh But the call to let connection = NSXPCConnection(machServiceName: com.myteam.myproject.service) let proxy = connection.remoteObjectProxyWithErrorHandler { error in continuation.resume(throwing: error) } as? MyServiceProtocol fails with The connection to service named com.myteam.m
Replies
6
Boosts
0
Views
1.5k
Activity
May ’26
Reply to CLLocationManager permission prompt never appears in Swift Playground
Solved! Thank you to everyone who responded. The issue: The location permission prompt never appeared when requestWhenInUseAuthorization() was called from within a SwiftUI sheet (modal view). iOS silently ignores permission requests made from inside sheets. The fix: Move the permission request to the parent view’s .onAppear modifier — before any sheet is presented. The LocationManager is created as a @StateObject in the main ContentView, requestPermission() is called in ContentView.onAppear, and the LocationManager instance is passed into the sheet view as an @ObservedObject. Key points: • The Core Location When in Use capability must be enabled in Swift Playgrounds app settings • Use @StateObject in the parent view, @ObservedObject in the sheet • Call requestWhenInUseAuthorization() from the main view, not from inside a sheet • startUpdatingLocation() can still be called from within the sheet’s .onAppear Hope this helps someone else!
Replies
Boosts
Views
Activity
May ’26