Explore the various UI frameworks available for building app interfaces. Discuss the use cases for different frameworks, share best practices, and get help with specific framework-related questions.

All subtopics
Posts under UI Frameworks topic

Post

Replies

Boosts

Views

Activity

A Summary of the WWDC25 Group Lab - UI Frameworks
At WWDC25 we launched a new type of Lab event for the developer community - Group Labs. A Group Lab is a panel Q&A designed for a large audience of developers. Group Labs are a unique opportunity for the community to submit questions directly to a panel of Apple engineers and designers. Here are the highlights from the WWDC25 Group Lab for UI Frameworks. How would you recommend developers start adopting the new design? Start by focusing on the foundational structural elements of your application, working from the "top down" or "bottom up" based on your application's hierarchy. These structural changes, like edge-to-edge content and updated navigation and controls, often require corresponding code modifications. As a first step, recompile your application with the new SDK to see what updates are automatically applied, especially if you've been using standard controls. Then, carefully analyze where the new design elements can be applied to your UI, paying particular attention to custom controls or UI that could benefit from a refresh. Address the large structural items first then focus on smaller details is recommended. Will we need to migrate our UI code to Swift and SwiftUI to adopt the new design? No, you will not need to migrate your UI code to Swift and SwiftUI to adopt the new design. The UI frameworks fully support the new design, allowing you to migrate your app with as little effort as possible, especially if you've been using standard controls. The goal is to make it easy to adopt the new design, regardless of your current UI framework, to achieve a cohesive look across the operating system. What was the reason for choosing Liquid Glass over frosted glass, as used in visionOS? The choice of Liquid Glass was driven by the desire to bring content to life. The see-through nature of Liquid Glass enhances this effect. The appearance of Liquid Glass adapts based on its size; larger glass elements look more frosted, which aligns with the design of visionOS, where everything feels larger and benefits from the frosted look. What are best practices for apps that use customized navigation bars? The new design emphasizes behavior and transitions as much as static appearance. Consider whether you truly need a custom navigation bar, or if the system-provided controls can meet your needs. Explore new APIs for subtitles and custom views in navigation bars, designed to support common use cases. If you still require a custom solution, ensure you're respecting safe areas using APIs like SwiftUI's safeAreaInset. When working with Liquid Glass, group related buttons in shared containers to maintain design consistency. Finally, mark glass containers as interactive. For branding, instead of coloring the navigation bar directly, consider incorporating branding colors into the content area behind the Liquid Glass controls. This creates a dynamic effect where the color is visible through the glass and moves with the content as the user scrolls. I want to know why new UI Framework APIs aren’t backward compatible, specifically in SwiftUI? It leads to code with lots of if-else statements. Existing APIs have been updated to work with the new design where possible, ensuring that apps using those APIs will adopt the new design and function on both older and newer operating systems. However, new APIs often depend on deep integration across the framework and graphics stack, making backward compatibility impractical. When using these new APIs, it's important to consider how they fit within the context of the latest OS. The use of if-else statements allows you to maintain compatibility with older systems while taking full advantage of the new APIs and design features on newer systems. If you are using new APIs, it likely means you are implementing something very specific to the new design language. Using conditional code allows you to intentionally create different code paths for the new design versus older operating systems. Prefer to use if #available where appropriate to intentionally adopt new design elements. Are there any Liquid Glass materials in iOS or macOS that are only available as part of dedicated components? Or are all those materials available through new UIKit and AppKit views? Yes, some variations of the Liquid Glass material are exclusively available through dedicated components like sliders, segmented controls, and tab bars. However, the "regular" and "clear" glass materials should satisfy most application requirements. If you encounter situations where these options are insufficient, please file feedback. If I were to create an app today, how should I design it to make it future proof using Liquid Glass? The best approach to future-proof your app is to utilize standard system controls and design your UI to align with the standard system look and feel. Using the framework-provided declarative API generally leads to easier adoption of future design changes, as you're expressing intent rather than specifying pixel-perfect visuals. Pay close attention to the design sessions offered this year, which cover the design motivation behind the Liquid Glass material and best practices for its use. Is it possible to implement your own sidebar on macOS without NSSplitViewController, but still provide the Liquid Glass appearance? While technically possible to create a custom sidebar that approximates the Liquid Glass appearance without using NSSplitViewController, it is not recommended. The system implementation of the sidebar involves significant unseen complexity, including interlayering with scroll edge effects and fullscreen behaviors. NSSplitViewController provides the necessary level of abstraction for the framework to handle these details correctly. Regarding the SceneDelagate and scene based life-cycle, I would like to confirm that AppDelegate is not going away. Also if the above is a correct understanding, is there any advice as to what should, and should not, be moved to the SceneDelegate? UIApplicationDelegate is not going away and still serves a purpose for application-level interactions with the system and managing scenes at a higher level. Move code related to your app's scene or UI into the UISceneDelegate. Remember that adopting scenes doesn't necessarily mean supporting multiple scenes; an app can be scene-based but still support only one scene. Refer to the tech note Migrating to the UIKit scene-based life cycle and the Make your UIKit app more flexible WWDC25 session for more information.
Topic: UI Frameworks SubTopic: General
0
0
664
Jun ’25
SwiftUI - Drag gesture blocks scroll gesture only on iPhone 11
I'm pretty new to Swift and SwiftUI. I'm making my first app for sorting a gallery with some extra features. I was using my own iPhone for testing and just started testing my app on other Apple products. Everything works fine on iPad Air M1, iPhone 15 Pro, iPhone 15 Pro Max, iPhone 13, iPhone XS (Simulator), and iPhone 11 Pro (Simulator). However, when I tried to show my app to a family member with an iPhone 11, I came across an issue. Issue Description: My app takes all photos from iPhone's native gallery, then you can sort it by some spesific filters and delete pictures. It just looks like the native gallery. (I can add photos later if needed) You can just scroll the gallery by swiping up and down. You can press the select button and start selecting pictures to delete. I recently added a drag-to-select-multiple-pictures feature. This makes it feel more like the native iOS experience, eliminating the need to tap each picture individually. However, on the iPhone 11, the moment you open the app, you can't scroll. Scrolling is completely locked. You can still select pictures by tapping or dragging, so it's not a touch area issue. The same issue persists on the iPhone 11 simulator. And I think I found the problematic part in my (sadly messy) ContentView.swift file; ScrollView { RefreshControl(coordinateSpace: .named("refresh")) { await viewModel.refreshMediaItems() } LazyVGrid(columns: gridColumns, spacing: UIDevice.current.userInterfaceIdiom == .pad ? 12 : 4) { let items = viewModel.filteredItems(typeFilter: mediaTypeFilter, specialFilter: specialFilter) ForEach(Array(zip(items.indices, items)), id: \.1.id) { index, item in MediaThumbnailView( item: item, isSelected: selectedItems.contains(item.id), viewModel: viewModel, onLongPress: { if !isSelectionMode { toggleSelectionMode() selectedItems.insert(item.id) } }, onTap: { if isSelectionMode { toggleSelection(item: item) } else { viewModel.selectItem(item) } } ) .aspectRatio(1, contentMode: .fit) .background( GeometryReader { geometry in let frame = geometry.frame(in: .named("grid")) Color.clear.preference( key: ItemBoundsPreferenceKey.self, value: [ItemBounds(id: item.id, bounds: frame, index: index)] ) } ) } } .padding(.horizontal, 2) .coordinateSpace(name: "grid") .onPreferenceChange(ItemBoundsPreferenceKey.self) { bounds in itemBounds = Dictionary(uniqueKeysWithValues: bounds.map { ($0.id, $0) }) itemIndices = Dictionary(uniqueKeysWithValues: bounds.map { ($0.id, $0.index) }) } .gesture( DragGesture(minimumDistance: 0) .onChanged { gesture in if isSelectionMode { let location = gesture.location if !isDragging { startDragging(at: location, in: itemBounds) } updateSelection(at: location, in: itemBounds) } } .onEnded { _ in endDragging() } ) } .coordinateSpace(name: "refresh") } you can see the .gesture(.... part. I realised that this DragGesture and ScrollView blocks each other (somehow only on iPhone 11) highPriorityGesture also won't work. When I change it with simultaneousGesture, scroll starts to work again. BUT - since it's simultaneous, when multiple selection mode is activated, when I'm dragging my finger gallery also starts to scroll and it becomes a very unpleasant experience. After this issue I realised on native gallery iOS locks scroll when you are dragging for multiple selection and just when you release your finger you can scroll again even if the multiple selection mode is active. I tried a million things, asked claude, chatgpt etc. etc. Found some similar issues on stackoverflow but they were all related to iOS 18, not spesific to an iPhone. My app works fine on iOS 18 (15 Pro Max) iOS 18 drag gesture blocks scrollview Here are the some of the things I've tried: using highPriorityGesture and simultenousgesture together, tried to lock the scroll briefly while dragging, implement much complicated versions of these things with the help of claude, try to check if isSelectionMode is true or not All of them broke other things/won't work. Probably there's something pretty simple that I'm just missing; but iPhone 11 being the single problematic device confuses me. I don't want to mess too much with my already fragile logic.
1
0
778
Jan ’25
What is the designated way to do custom background drawing in TextKit 2 when using UITextView/NSTextView?
In TextKit 1, I can override drawBackground(forGlyphRange:at:) in NSLayoutManager to do custom background drawing. However, I'm not too sure what the designated way of doing background drawing is in TextKit 2. One thing I've tried is to do custom drawing in my own CALayer that's used in the configureRenderingSurface delegate callback, but I'm unsure if we are suppose to use this API and steal the textViewportLayoutController.delegate away from _UITextLayoutcanvasView?
4
0
2.9k
Jan ’25
AppIntents - Choosing a default Measurement<UnitMass> for body weight based on locale
Here’s a clearer and more concise version of your question: I’m creating an AppIntent to allow users to log their body weight. My intent includes a @Parameter defined as: @Parameter( title: "Weight", description: "Current Weight", defaultUnit: .pounds, supportsNegativeNumbers: false ) var weight: Measurement<UnitMass> This works but doesn’t respect the user’s Locale and its measurementSystem. When I add defaultUnitAdjustForLocale: true to the @Parameter macro, the default always switches to kilograms, regardless of the locale. How can I correctly set the default unit to match the user’s locale for the purpose of entering a users body weight?
0
0
370
Jan ’25
SwiftUI TabView with .page Style: GeometryReader minX Not Updating on Page Scroll
I am working on a SwiftUI TabView with the .page style (indexDisplayMode: .never). I want to track the minX property of each tab's view using GeometryReader. However, I noticed inconsistent behavior when scrolling between pages. Here's the simplified code: import SwiftUI struct ContactScreenView: View { let text: String var body: some View { ZStack { Color.red.opacity(0.4).ignoresSafeArea() VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text(text) } .padding() } } } struct DemoView: View { @State private var selectedTab: Int = 0 var body: some View { VStack { TabView(selection: $selectedTab) { ContactScreenView(text: "followers") .background( GeometryReader(content: { geometry -> Color in let minX = geometry.frame(in: .global).minX print(minX) return Color.clear }) ) .tag(0) ContactScreenView(text: "following") .tag(1) ContactScreenView(text: "blocked") .tag(2) ContactScreenView(text: "Shared") .tag(3) } .tabViewStyle(.page(indexDisplayMode: .never)) } } } #Preview { DemoView() } Observed Behavior: When I scroll to the second page (index 1), the minX value updates correctly to screenWidth * 1, as expected. When I scroll to the third page (index 2), the minX value doesn't update at all. The ideal behavior would be for minX to update to screenWidth * 2 for the third page and so on, for subsequent pages. Expected Behavior: The minX value should correctly reflect the global position of each page as I scroll through the TabView. For example: Page 0: minX = 0 Page 1: minX = screenWidth * 1 Page 2: minX = screenWidth * 2 And so on.
Topic: UI Frameworks SubTopic: SwiftUI
1
0
264
Jan ’25
In iOS 18, UINavigationController continuously executes pushViewController, and the lifecycle method is not executed when the viewController enters the stack
let home = homeViewController() let rootNav = UINavigationController(rootViewController: home) window?.rootViewController = rootNav window?.makeKeyAndVisible() let second = SecondViewController() home.navigationController?.pushViewController(second, animated: false) let third = ThirdViewController() home.navigationController?.pushViewController(third, animated: false) After the above is executed, the viewdidload and other related lifecycle methods in the SecondViewController are not executed。 Except for iOS18, other versions don't have this problem, so it's not a bug in iOS18, or iOS18 has optimized UINavigationController
Topic: UI Frameworks SubTopic: UIKit
2
0
584
Jan ’25
iPadOS 18 App (on Apple Silicon) - Duplicate Tab Bar Appearing in Toolbar
With iPadOS 18, the UITabBar now defaults to the floating style. I successfully reverted the tab bar to its traditional style by overriding the UITabBarController's horizontalSizeClass property: self.tabBarController?.traitOverrides.horizontalSizeClass = .unspecified When I launch the app on my Mac using Apple Silicon, TWO tab bars appear: One appears at the bottom of the screen, like a traditional tab bar. The second tab bar is still embedded in the app toolbar in its floating style. Is this a bug? How do you ensure that overriding the horizontalSizeClass will remove/hide the floating tab bar when running an app on Apple Silicon? TIA! (Demonstrated on a test project)
0
0
484
Jan ’25
SwiftUI PKCanvasView bounds
I am creating a Bible app with SwiftUI using Text in the background and a PKCanvasView in the front to mark the text and take notes. The user can modify the font and its size and you can navigate to different books and chapters. Each chapter's text has a different size causing the PKCanvasView to have varying sizes. The width of the canvas is always the same but the height changes based on these parameters I just mentioned. If the chapter is long and the height of the canvas exceeds 4000 or some settings cause the text to make the views bound to go beyond 4000, the drawing will enlarge or appear to be occurring in a different location than my pencil. As soon as I lift my pencil, the drawing snaps to the place it belongs. var body: some View { HStack(spacing: 0) { // Main content container ScrollView { ZStack { // Text content VStack { if let chapter = viewModel.currentChapterText { HStack { Text(AttributedString(chapter.html(fontName: fontName, fontSize: fontSize, showVerses: showVerse, showFootnotes: showFootnotes))) .padding() .frame(width: textWidth, alignment: .leading) Color.clear } .frame(width: canvasWidth) } else { Text("Select a book to begin reading") .foregroundColor(.gray) } } // Drawing canvas overlay if showingDrawingTools { DrawingCanvasView( canvasView: $canvasView, toolPicker: toolPicker, frame: CGSize(width: deviceWidth, height: deviceHeight), onSave: saveDrawing ) } } } } .onChange(of: viewModel.currentChapter) { oldValue, newValue in print("BibleContentView - chapter text changed") } }
Topic: UI Frameworks SubTopic: SwiftUI
2
0
269
Jan ’25
Numerous Undefined symbol errors
Getting these two warnings: Could not find or use auto-linked framework 'CoreAudioTypes': framework 'CoreAudioTypes' not found Could not parse or use implicit file '/Applications/Xcode16.0/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore.tbd': cannot link directly with 'SwiftUICore' because product being built is not an allowed client of it Followed by 100 + errors like below Undefined symbol: _TIFFCleanup & Undefined symbol: _TIFFReadRGBAImageOriented ..... Any ideas? I have tried adding CoreAudioTypes etc. Error is not clear. Am trying to stop using Rosetta
Topic: UI Frameworks SubTopic: General
2
0
781
Dec ’24
"Add-on" services no longer supported?
Our MacOS app has for some time been able to create so-called "add-on" services, which are dynamically written to individual bundles in ~/Library/Services/ (as opposed to being statically defined in the app's Info.plist). These worked fine for a long time until recently. They still appear in other app Services menus, but do not get as far as calling the specified instance method in our app. Does anyone know if add-on services are no longer supported? Perhaps due to some new security constraint? The documentation on app services in general seems to be out of date. I did try copying the add-on service definition from the add-on plist into the app's Info.plist. That seemed to work, so the basic specification doesn't seem to have changed.
Topic: UI Frameworks SubTopic: AppKit
0
0
272
Jan ’25
UIimage init crash for old Xcode
We have found some recent crashes that only appear on iOS 18 iPad OS 18, these crashes only appear in apps packaged in August 2022 and earlier and affect about 200 users per day, the same method calls have not had the same crashes in any of the subsequent Xcode build, here's the code in question. public class FeedComponentResource: NSObject { static func bundle() -> Bundle? { let path = (Bundle(for: FeedComponentResource.self).resourcePath! as NSString).appendingPathComponent("ResourceBundle.bundle") let bundle = Bundle(path: path) return bundle } public static func image(_ id: String) -> UIImage { var image = UIImage() if let bundle = self.bundle() { // crashed in this line image = UIImage(named: id, in: bundle, compatibleWith: nil)! } return image } and here is the call stack EXC_BREAKPOINT 0x000000010302b328 Crashed: com.apple.main-thread 0 NewsBreak 0x60b328 closure #1 in FeedComponentHeader.authorIconView.getter + 3256176 (FeedComponentResource.swift:3256176) 1 NewsBreak 0x6081b0 FeedComponentHeader.authorIconView.getter + 3243512 2 NewsBreak 0x6086ac FeedComponentHeader.init(frame:) + 94 (FeedComponentHeader.swift:94) 3 NewsBreak 0x609550 @objc FeedComponentHeader.init(frame:) + 3248536 (<compiler-generated>:3248536) 4 NewsBreak 0x241c00 closure #1 in FeedNewsRedesignBaseCell.header.getter + 17 (FeedNewsRedesignBaseCell.swift:17) 5 NewsBreak 0x241134 FeedNewsRedesignBaseCell.header.getter + 4332327220 6 NewsBreak 0x2452a0 FeedNewsRedesignBaseCell.init(frame:) + 160 (FeedNewsRedesignBaseCell.swift:160) 7 NewsBreak 0x245618 @objc FeedNewsRedesignBaseCell.init(frame:) + 4332344856 (<compiler-generated>:4332344856) 8 NewsBreak 0x249350 FeedNewsRedesignBigCell.init(frame:) + 16 (FeedNewsRedesignBigCell.swift:16) 9 NewsBreak 0x24a5b0 @objc FeedNewsRedesignBigCell.init(frame:) + 4332365232 (<compiler-generated>:4332365232) 10 UIKitCore 0x82110 __88-[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:]_block_invoke + 40 11 UIKitCore 0x7ff30 +[UIView(Animation) performWithoutAnimation:] + 76 12 UIKitCore 0x27a180 -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 956 13 UIKitCore 0x279d48 -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:] + 84 14 NewsBreak 0x6f1e8 -[FeedViewController collectionView:cellForItemAtIndexPath:] + 1951 (FeedViewController.m:1951) 15 UIKitCore 0x9f6340 __112-[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:]_block_invoke.394 + 52 16 UIKitCore 0x7ff30 +[UIView(Animation) performWithoutAnimation:] + 76 17 UIKitCore 0x2782d4 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 1208 18 UIKitCore 0x2779b0 -[UICollectionView _createVisibleViewsForSingleCategoryAttributes:limitCreation:fadeForBoundsChange:] + 524 19 UIKitCore 0x3a2aa8 -[UICollectionView _createVisibleViewsForAttributes:fadeForBoundsChange:notifyLayoutForVisibleCellsPass:] + 300 20 UIKitCore 0x1acf18 -[UICollectionView _updateVisibleCellsNow:] + 3092 21 UIKitCore 0x3057c4 -[UICollectionView layoutSubviews] + 288 22 UIKitCore 0xd688 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2424 23 QuartzCore 0x78c28 CA::Layer::layout_if_needed(CA::Transaction*) + 496 24 UIKitCore 0x50138 -[UIView(Hierarchy) layoutBelowIfNeeded] + 312 25 UIKitCore 0xde5a4 -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:animator:animationHandler:] + 288 26 NewsBreak 0x6db5c -[FeedViewController updateCollection:updates:completion:] + 1791 (FeedViewController.m:1791) 27 NewsBreak 0x112348 -[FeedProvider startUpdateCollection:] + 1067 (FeedProvider.m:1067) 28 libdispatch.dylib 0x2370 _dispatch_call_block_and_release + 32 29 libdispatch.dylib 0x40d0 _dispatch_client_callout + 20 30 libdispatch.dylib 0x129e0 _dispatch_main_queue_drain + 980 31 libdispatch.dylib 0x125fc _dispatch_main_queue_callback_4CF + 44 32 CoreFoundation 0x56204 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 33 CoreFoundation 0x53440 __CFRunLoopRun + 1996 34 CoreFoundation 0x52830 CFRunLoopRunSpecific + 588 35 GraphicsServices 0x11c4 GSEventRunModal + 164 36 UIKitCore 0x3d2eb0 -[UIApplication _run] + 816 37 UIKitCore 0x4815b4 UIApplicationMain + 340 38 NewsBreak 0xa6dc main + 17 (main.m:17) Looking forward to the subsequent iOS version can fix this problem can reduce the impact on online users, thank you!
Topic: UI Frameworks SubTopic: UIKit
2
0
306
Dec ’24
TextField using numberPad shows incorrectly shows autofill for one time code
If I show a textfield in my app and set nothing else on it but the following, The keyboard will show an autofill suggestion from a password manager for a one time code. textField.keyboardType = .numberPad In this case, the text field is for typing in a count, so iOS suggesting to autofill a one time code is incorrect. Setting textField.textContentType to nil has no affect on the behaviour. Prerequisites to reproduce an app with an associated domain an entry in a password manager with a one time code for the domain a textfield with keyboardType set to numberPad
Topic: UI Frameworks SubTopic: UIKit Tags:
2
0
657
Feb ’25
SwiftUI Animation - Spooky Action At A Distance
I have a grid-like container with subviews. I recently changed some internal details of the subviews, so that changes to the values they display animate. Now, the behaviour of the grid container has changed: the animation duration used for the internal changes is now also used when the grid is re-ordered or subviews are added or removed. I can see why this happens: the grid repositions the subviews, and the subview has declared an animation that applies to all of its properties however they are modified. This doesn't seem like a good idea to me. The principle of encapsulation suggests that I should be able to make internal changes to a component without suffering "spooky action at a distance", i.e. other components unexpectedly changing their behaviour. Is this an inherent issue with SwiftUI animations, or does it suggest that I am doing something wrong?
1
0
319
Jan ’25
How do I obtain the preview image for a PDF?
I have a SwiftUI view of the form struct ContentView: View { // ... .onDrop(of: [.pdf], isTargeted: $isDropTargeted) { pdfs in for pdf in pdfs { I'm just not sure what to do next, I see there's a loadPreviewImage() that if I use like: Task.detached { // returns any NSSecureCoding object let image = try! await pdf.loadPreviewImage() } Not sure how I'm supposed to get my preview image from that NSSecureCoding object
Topic: UI Frameworks SubTopic: SwiftUI
0
0
233
Jan ’25
Screen capture notification in MacOs catalyst
We have a IOS app and we are using the same app for Mac Catalyst. In IOS we are able to detect when user take the screenshot using UIApplicationUserDidTakeScreenshotNotification. But in MACCatalyst it is not working. As per docs UIApplicationUserDidTakeScreenshotNotification and UIScreenCapturedDidChangeNotification are both supported for MacCatalyst 13.1+. But I am not getting screen shot notifications using both
3
0
498
Feb ’25
Keyboard will not show when setting focus on a SwiftUI text field from a button in an ornament on visionOS
Using a button that is placed in the bottom ornament to set focus on a text field will not display the keyboard properly while a button embedded in the view will behave as expected. To demonstrate the issue, simply run the attached project on Vision Pro with visionOS 1.1 and tap the Toggle 2 button in the bottom ornament. You’ll see that the field does have focus but the keyboard is now visible. Run the same test with Toggle 1 and the field will get focus and the keyboard will show as expected. import SwiftUI import RealityKit import RealityKitContent struct ContentView: View { @State private var text = "" @State private var showKeyboard = false @FocusState private var focusedField: FocusField? private enum FocusField: Hashable { case username case password } var body: some View { VStack { TextField("Test", text: $text) .focused($focusedField, equals: .username) Text("Entered Text: \(text)") .padding() Button("Toggle 1") { // This button will work and show the keyboard if focusedField != nil { focusedField = nil } else { focusedField = .username } } Spacer() } .padding() .toolbar { ToolbarItem(placement: .bottomOrnament) { Button("Toggle 2") { // This button will set focus properly but not show the keyboard if focusedField != nil { focusedField = nil } else { focusedField = .username } } } } } } Is there a way to work around this? FB13641609
1
0
757
Jan ’25