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

RealityKit attachments on macOS?
I'm building a SwiftUI+RealityKit app for visionOS, macOS and iOS. The main UI is a diorama-like 3D scene which is shown in orthographic projection on macOS and as a regular volume on visionOS, with some SwiftUI buttons, labels and controls above and below the RealityView. Now I want to add UI that is positioned relative to some 3D elements in the RealityView, such as a billboarded name label over characters with a "show details" button and such. However, it seems the whole RealityView Attachments API is visionOS only? The types don't even exist on macOS. Why is it visionOS only? And how would I overlay SwiftUI elements over a RealityView using SwiftUI code on macOS if not with attachments?
1
0
442
Dec ’24
How can the long - press gesture act only on a certain element in a list item?
I use the effect in the picture to do the test, I want to achieve a habit of multiple punch card effect, click to complete a punch card, long press to cancel a punch card. I'm having a problem right now. I want the long press gesture to only work on the trash icon, not extend to the entire item, causing the entire item to be highlighted. What should I do about it? I tried a lot of methods, but I didn't achieve the effect.
0
0
214
Dec ’24
Position of volumetric and 2D windows on visionOS
Hi, I would like to create an app that has a volumetric window in the middle and two 2D windows on the sides. When I tried that, the 2D windows are positioned slightly below the volumetric window for some reason (image1). Looks like the base (hadle, close button, etc.) of the volumetric window is aligned with the center of the whole 2D window. I would like all the window bases to be aligned (image2). (I can of course do this manually by dragging the window down a bit with my hand, but that’s an inconvenience for my usecase.) I tried making the whole volumetric window content higher, but that did not help and the content actually went far above the 2D windows (image3). I suppose this was some design choice when creating the whole window positioning behavior on VisionOS. Am I doing something wrong? Is there a way to achieve what I want or a better way to customize the position of windows, not just 5 predefined positions in defaultWindowPlacement? Image1 - current: Image2 - what I want: Image3 - current, larger content: Code: import SwiftUI @main struct placementTestApp: App { @Environment(\.openWindow) var openWindowAction var body: some Scene { WindowGroup(id: "volume") { VolumetricWindowView() .onAppear { openWindowAction(id: "first") openWindowAction(id: "second") } } .windowStyle(.volumetric) .volumeWorldAlignment(.gravityAligned) WindowGroup(id: "first") { NormalWindowView() } .defaultWindowPlacement { _, context in if let mainWindow = context.windows.first(where: { $0.id == "volume" }) { WindowPlacement(.leading(mainWindow)) } else { WindowPlacement() } } WindowGroup(id: "second") { NormalWindowView() } .defaultWindowPlacement { _, context in if let mainWindow = context.windows.first(where: { $0.id == "volume" }) { WindowPlacement(.trailing(mainWindow)) } else { WindowPlacement() } } } }
1
0
401
Dec ’24
Deriving Apple Place ID from CLPlacemark or MKMapItem
I am trying to derive the Apple Place ID from a CLPlacemark (or via a MKMapItem derived from it) created via either CLGeocoder().reverseGeocodeLocation() or CLGeocoder().geocodeAddressString(). In many cases, the placemark returned from these functions contains detailed information (name, address, coordinates, etc), implying that the Apple Place ID is known, but the identifier is not present. The only way I have found to get a Place ID is via MKLocalSearch. Wondering if I am missing something here.
2
1
472
Dec ’24
@AppStorage with Date in SwiftUI
Hello I want to be able to save Date in @AppStorage, and it works however I was wondering what was the difference between these two extensions, which one is better and why? extension Date: RawRepresentable { static var dateFormatter: DateFormatter = { let formatter = DateFormatter() formatter.dateStyle = .long return formatter }() public var rawValue: String { Date.dateFormatter.string(from: self) } public init?(rawValue: String) { self = Date.dateFormatter.date(from: rawValue) ?? Date() } } and extension Date: RawRepresentable { private static let formatter = ISO8601DateFormatter() public var rawValue: String { Date.formatter.string(from: self) } public init?(rawValue: String) { self = Date.formatter.date(from: rawValue) ?? Date() } } Thank You!
5
0
6.1k
Dec ’24
TextKit2 : - The text inserted between the attributedText(Paragraph) doesn't inherit the attributes of existing text
I have added an custom attribute for a paragraph using the below method textStorage.addAttribute(.customCase, value: "checkList", range: paragraphRange) When I insert some text in between the text which contains the custom attribute, that text is not inheriting/propagating the custom attribute of existing paragraph text Old Text : - This is a test New Text : - This is "some new" a test The inserted part is not getting the custom attribute of the old text, Can I know why it's happening, Is it some textKit2's behaviour.
0
0
410
Dec ’24
iOS 18 SwiftUI List with animation modifier has unexpected behaviour
Noticed in iOS 18 that List element with animation modifier behaves differently. Seems that on first change of the underlying State property List updates all elements and loses its scroll position even if you insert just one element. The following code reproduces the behaviour, if you run it on iOS 17 it will behave as expected, you'll see an element being added to the list with an acompanying animation. On iOS 18 you'll lose your scroll position and judging by the animation it seems to update all the other rows in the list even though only one element of the underlaying State property was inserted. After that first update, list element on iOS will behave as expected. To reproduce the issue scroll down to the ~50th element and tap on a row, compare the behaviour on iOS 17 and iOS 18. import SwiftUI struct ContentView: View { struct ViewState: Equatable { struct Value: Identifiable, Equatable { let id: String var text: String var value: Bool } let list: [Value] } @State var viewState: [ViewState.Value] = { return (0..<100).map { id in ViewState.Value( id: "\(id)", text: "Row number: \(id + 1)", value: Bool.random() ) }}() var body: some View { list(viewState) } @ViewBuilder private func list(_ list: [ViewState.Value]) -> some View { List { ForEach(list) { row in self.value(row) } } .animation(.default, value: viewState) } @ViewBuilder private func value(_ value: ViewState.Value) -> some View { Button(action: { guard let rowIndex = viewState.firstIndex(where: { $0.id == value.id }) else { return } viewState.insert(randomValue(id: rowIndex), at: rowIndex + 1) }) { VStack { Text(value.text) Text("\(value.value ? "ON" : "OFF")") .foregroundStyle(value.value ? Color.green : Color.red) } } } private func randomValue(id: Int) -> ContentView.ViewState.Value { let id = (id*100 + 1) return .init(id: "New id: \(id)", text: "Row number: \(id)", value: Bool.random()) } } Issues has already been reported using feedback assistant FB16082730
0
1
448
Dec ’24
UIWritingToolsCoordinator.Context Lifetime?
What is the lifetime of a UIWritingToolsCoordinator.Context object? The UIWritingToolsCoordinator.Delegate API expects you to maintain a reference to the context identifiers you create in writingToolsCoordinator(:contextsFor:) to be able to return them in writingToolsCoordinator(:rangeInContextWithIdentifierFor:). At some point, you need to release these references. Can you, for example, assume that the context will not be referenced after writingToolsCoordinator(_:willChangeToState:) is called with a state of .inactive?
Topic: UI Frameworks SubTopic: UIKit
0
1
283
Dec ’24
Programmatically change TabViewCustomization for iOS 18/iPad?
I have a TabView with a TabViewCustomization var, with customizationIDs set for all tabs. I have one tab set to .defaultVisibility(.hidden, for: .tabBar, .sidebar). This works as expected; initially, that tab isn't visible in either the tabBar or sidebar; with the sidebar open, I can click Edit and toggle the visibility. So far, so good. Is there a way that I can programmatically change the visibility? For example, folks with the Admin role should see the tab by default, while those with the User role shouldn't. If this is possible, can I hide the Edit button on the sidebar so the visibility can only be changed programmatically?
Topic: UI Frameworks SubTopic: SwiftUI
3
0
296
Dec ’24
Hide header animated from UICollectionViewCompositionalLayout
Hello! I have a collectionView and assigned a layout to it: collectionView.collectionViewLayout = createLayout(hasHeader: true) func createLayout(hasHeader: Bool) -> UICollectionViewCompositionalLayout { let layout = UICollectionViewCompositionalLayout { [weak self] (section,environment) -> NSCollectionLayoutSection? in // configure cells } // adding a header: if hasHeader { let header = //... layout.boundarySupplementaryItems.append(header) } return layout } Now, I just want to hide the header (animated). Removing the header can simply be done this way, but this is not animated: collectionView.collectionViewLayout = createLayout(hasHeader: false) Is there any other possibility to hide it animated?
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
332
Dec ’24
LiveActivity UI not showing in flutter ios app
I'm implementing iOS Live Activities in my Flutter app using the live_activities package. While the activity seems to be created (I can get the activity token, and clicking the Dynamic Island opens the app), the LiveActivity UI does not show up as expected. Logs: The following errors/warnings appear in the logs: Not updating lastKnownShmemState in CFPrefsPlistSource<0x6000006bc7e0> (Domain: group.powerdock.sessionactivity, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): 34 -> 33 What Works: The activity token is created successfully. Clicking the Dynamic Island opens my app. What Does Not Work: The LiveActivity UI does not display on the lock screen or elsewhere.
1
0
585
Dec ’24
How to update data in a DataFrame
My project loads a CSV into a DataFrame and displays it in a Table (a MacOS app). So far so good ... but when trying to update a value in a column, I dont see anyway to update this value. The table gets the value for the column like this: func getColumnValue(row :DataFrame.Rows.Element, columnName :String) -&gt; String { if row.base.containsColumn(columnName) { var value = "" if row[columnName] != nil { value = "\(row[columnName]!)" } return value } ... But the documentation and googles dont show any way to update the same column. Any help is appreciated with cookies. Attempt to update: func setColumnValue(row :DataFrame.Rows.Element, columnName :String, value :String) { var column: [String?] = data[columnName] column[row.id] = value ... }
6
0
664
Dec ’24
FocusState and pickers error
Hello, since the last version of iOS and WatchOS I have a problem with this code. This is the minimal version of the code, it have two pickers inside a view of a WatchOS App. The problem its with the focus, I can't change the focus from the first picker to the second one. As I said before, it was working perfectly in WatchOS 10.0 but in 11 the problems started. struct ParentView: View { @FocusState private var focusedField: String? var body: some View { VStack { ChildView1(focusedField: $focusedField) ChildView2(focusedField: $focusedField) } } } struct ChildView1: View { @FocusState.Binding var focusedField: String? @State private var selectedValue: Int = 0 var body: some View { Picker("First Picker", selection: $selectedValue) { ForEach(0..<5) { index in Text("Option \(index)").tag("child\(index)") } }.pickerStyle(WheelPickerStyle()).focused($focusedField, equals: "first") } } struct ChildView2: View { @FocusState.Binding var focusedField: String? @State private var selectedValue: Int = 0 var body: some View { Picker("Second Picker", selection: $selectedValue) { ForEach(0..<5) { index in Text("Option \(index)").tag("childTwo\(index)") } }.pickerStyle(WheelPickerStyle()).focused($focusedField, equals: "second") } } When you do vertical scrolling on the second picker, the focus should be on it, but it dosnt anything. I try even do manually, setting the focusState to the second one, but it sets itself to nil. I hope that you can help me, thanks!
4
0
1.2k
Dec ’24
SwiftUI Animation very Laggy on iOS 18 Release only
Dear Experts, I created a SwiftUI View (in a UIKit based project) whose objective is to display a short animation in the front of the user screen. I developed it 8 month ago in XCode 15 for iOS 17, no problems. But since iOS 18, I can observe huge lags on my animation only in Release app. The problem is not present in Debug app. I don't understand why this problem occurs, the animation is quite simple, it's just an offset deplacement. I tried many thing like: Show the animation with a UINavigationController Show the animation with a UIWindow Move the view with .position Remove the GeometryReader All other animation withAnimation and .animation Task and DispatchQueue Etc... I found that the laggy animation occurs when I set the Optimization Level for the Swift Compiler - Code Generation to Optimize for Speed [-O]. That's very strange because we had this option on Release for iOS 17 and we had no lags... I can share to you a Sample Repository with the configuration we have. https://github.com/Thibma/sample-animation-swiftui Today the only option I used is to develop this feature in UIKit but it's too bad to skip the SwiftUI opportunity. :/ If you have any ideas to resolve this, I take ! Thank you !
0
0
549
Dec ’24
SwiftUI .fileImporter does not react to isPresented change.
I made a ImagePicker which worked pretty well. But when app get bigger it stops. Does not react to change isPresented value. As far I know I changed nothing around this part of an App. Also same thing happened in different place, another kind of picker. print ("HELL'o") never prints. Silence. struct ImagePicker: View { @Binding var imageSource: ImageSource @State var showFileImporter: Bool = false @EnvironmentObject var manager: Manager var body: some View { VStack { .... Button(action: { print("before", showFileImporter) showFileImporter = true print("after", showFileImporter) }, label: { Text("open Image") }) .buttonStyle(.borderless) .controlSize(.mini) }.fileImporter(isPresented: $showFileImporter, allowedContentTypes: [.png, .jpeg, .tiff], onCompletion: { result in print ("HELL'o") // Never prints switch result { case let .success(url): guard let _ = try? Data(contentsOf: url) else { return } .... case let .failure(error): print(error) } }) } } Does anybody have an idea what happened? I suspect some settings in completely different palce or bug or computer does not like me.
0
0
309
Dec ’24
Regarding the display of AppleArcade access points when playing iOS apps on visionOS.
[The problem that is occurring] The game apps in development are compatible with iOS, macOS, tvOS, and visionOS. In the Game app under development, the AppleArcade access point is placed in the main menu. In visionOS, when the main menu is opened, the GameCenter dashboard is automatically launched within 1~2 seconds after the main menu is displayed. This condition occurs every time the menu is re-opened. On iOS, macOS, and tvOS, the dashboard appears after pressing the GameCenter access point icon. [What you want to solve] We would like to make it so that the Game Center dashboard is launched after the access point icon is pressed on visionOS as it is on other operating systems. Or, if there is a standard implementation method for visionOS, please let us know.
1
0
517
Dec ’24
SwiftUI List .scrollPosition not working
Hi, I am trying to read in which section in a list the user is currently located and want to scroll him to a specific section. Therefore I would like to use the new .scrollPosition modifier. Best would be the ability to implement the same snapping effect from ScrollView. So I used this snippet: struct Item: Identifiable{ var id: Int static func getMany() -> [Item] { var items = [Item]() for i in 0..<100 { items.append(Item(id: i)) } return items } } struct ContentView: View { @State var items = Item.getMany() @State var scrolledID: Item.ID? var body: some View { NavigationStack { List { ForEach(items) { item in ItemView(item: item) } } .scrollTargetLayout() .scrollPosition(id: $scrolledID) .navigationTitle("Hello, \(scrolledID ?? 0)") } } } struct ItemView: View { var item: Item var body: some View { Text("Hello world, \(item)") } } Doesn't work. So I tried to place the modifiers in different places in the code to attack several different parts of the list as the "scrollTargetLayout" - but this doesn't change anything here. Isn't the List View just the Form inside a ScrollView?! This doesn't work either. If I place the Form OR List inside a ScrollView, the contents of the list aren't displayed anymore. This seems logical, because the list is a LazyVStack rendering without a height, as it doesn't know its final height. Can we fix this somehow?
2
0
593
Dec ’24