Search results for

“swiftui”

17,107 results found

Post

Replies

Boosts

Views

Activity

How do I dismiss a presented sheet?
I'm developing an app requiring data entry across several devices. My SwiftUI app runs on iOS and iPadOS but I also want to run it on visionOS. I'm using the visionOS simulator. When I enter data in one of my views I use a Form within a .sheet and this works perfectly well on iOS and iPadOS and I can dismiss the sheet by simply tapping the view behind the sheet. On visionOS I click my + button, the sheet appears, I enter the data as usual but after that there is no gesture in the app I can perform with keyboard or mouse that will make the sheet disappear! Do I have to add a Close button for visionOS or is there a way to enable the same interaction that works on iPadOS?
1
0
914
2w
Reply to App crashes in CGFontStrikeRelease
Adding a data point to this thread. We're seeing the exact same stack chain — _os_unfair_lock_corruption_abort → _os_unfair_lock_lock_slow → CGFontStrikeGetSize → CGGlyphBuilderUnlockBitmaps → render_glyphs → CA::Transaction::commit → _UIApplicationFlushCATransaction — deterministically reproducing on iPhone 17 Pro Max + iOS 26.4.2 (build 23E261) during a SwiftUI Setup→Session view transition while CoreML models are warming and an AVAudioEngine is starting. Filed as FB22728399 on 2026-05-08, with 6 byte-identical .ips reports and a full sysdiagnose attached. A few additions to the existing reports here: Negative MallocStackLogging result. Crash reproduces with MallocStackLogging + MallocScribble + MallocPreScribble + MallocGuardEdges all simultaneously active. Zero malloc diagnostics fire. The corrupting write is not in user-managed heap. Co-occurring signal. 8× AVAudioBuffer.mm:281 mBuffers[0].mDataByteSize (0) should be non-zero warnings during the same model-compile window in which the lock corrup
Topic: UI Frameworks SubTopic: UIKit Tags:
2w
Why doesn't .glassEffect tint render on a Menu in an iOS 26 toolbar?
This is what I am trying to achieve (from the Phone app, similar one is also in Photos) I have a standard SwiftUI Menu in a toolbar with a glass tint applied to indicate the filter is active: Menu { // …filter options } label: { Label(Filter, systemImage: line.3.horizontal.decrease) } .glassEffect(.regular.tint(.accentColor).interactive()) The glass effect doesn't render at all, no tint. The button looks completely unstyled. If I switch the label from Label to Image, the glass renders, but as a stretched oblong pill. I have tried several other combinations too: Also in the Apple's version during hover (iPad) the highlight aligns with the tint itself (see second image above) rather than outside it like in example 3 from the list above: Is there a way to get a Menu's trigger inset tint to look as in the Phone app example?
0
0
103
2w
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
951
3w
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
0
0
224
3w
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
598
3w
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:
3w
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
3w
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
826
3w
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
208
3w
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
202
3w
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
67
3w
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:
3w
How do I dismiss a presented sheet?
I'm developing an app requiring data entry across several devices. My SwiftUI app runs on iOS and iPadOS but I also want to run it on visionOS. I'm using the visionOS simulator. When I enter data in one of my views I use a Form within a .sheet and this works perfectly well on iOS and iPadOS and I can dismiss the sheet by simply tapping the view behind the sheet. On visionOS I click my + button, the sheet appears, I enter the data as usual but after that there is no gesture in the app I can perform with keyboard or mouse that will make the sheet disappear! Do I have to add a Close button for visionOS or is there a way to enable the same interaction that works on iPadOS?
Replies
1
Boosts
0
Views
914
Activity
2w
Reply to Detect SD Card
Yes - it was my lack of familiarity with the communication between a SwiftUI application and this type of framework.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
2w
Reply to App crashes in CGFontStrikeRelease
Adding a data point to this thread. We're seeing the exact same stack chain — _os_unfair_lock_corruption_abort → _os_unfair_lock_lock_slow → CGFontStrikeGetSize → CGGlyphBuilderUnlockBitmaps → render_glyphs → CA::Transaction::commit → _UIApplicationFlushCATransaction — deterministically reproducing on iPhone 17 Pro Max + iOS 26.4.2 (build 23E261) during a SwiftUI Setup→Session view transition while CoreML models are warming and an AVAudioEngine is starting. Filed as FB22728399 on 2026-05-08, with 6 byte-identical .ips reports and a full sysdiagnose attached. A few additions to the existing reports here: Negative MallocStackLogging result. Crash reproduces with MallocStackLogging + MallocScribble + MallocPreScribble + MallocGuardEdges all simultaneously active. Zero malloc diagnostics fire. The corrupting write is not in user-managed heap. Co-occurring signal. 8× AVAudioBuffer.mm:281 mBuffers[0].mDataByteSize (0) should be non-zero warnings during the same model-compile window in which the lock corrup
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
2w
Why doesn't .glassEffect tint render on a Menu in an iOS 26 toolbar?
This is what I am trying to achieve (from the Phone app, similar one is also in Photos) I have a standard SwiftUI Menu in a toolbar with a glass tint applied to indicate the filter is active: Menu { // …filter options } label: { Label(Filter, systemImage: line.3.horizontal.decrease) } .glassEffect(.regular.tint(.accentColor).interactive()) The glass effect doesn't render at all, no tint. The button looks completely unstyled. If I switch the label from Label to Image, the glass renders, but as a stretched oblong pill. I have tried several other combinations too: Also in the Apple's version during hover (iPad) the highlight aligns with the tint itself (see second image above) rather than outside it like in example 3 from the list above: Is there a way to get a Menu's trigger inset tint to look as in the Phone app example?
Replies
0
Boosts
0
Views
103
Activity
2w
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
951
Activity
3w
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
0
Boosts
0
Views
224
Activity
3w
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
598
Activity
3w
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
3w
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
3w
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
826
Activity
3w
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
208
Activity
3w
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
93
Activity
3w
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
202
Activity
3w
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
67
Activity
3w
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
3w