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

Post

Replies

Boosts

Views

Activity

UISplitViewController and UITabBarController in iOS 15 is always full screen
I'm reworking my app and update code and design. Because my app is one both iPhone and iPad, i'm using Splitview to handle the configurations. But my app has 4 section that I manage using a Tab bar and each tab has a SplitView. As you can see in images, the problem is that if I attach directly the UISplitViewController to UITabBarController you don't see two columns but only one (the primary or secondary view) both iPhone landscape orientation and iPad. A solution that I found is to attach the splitviewcontroller to a view that contains a ContainerViewController e connect the split view to this container. If you do this, you see the split view work correctly ma the problem is the customization of appearance (look at image 3) So may questions are: why I have to embed a split view in a container view controller and i can't connect it directly to tabbar as we done until now? Is there an other better solution then put a split view in a containerView? Thank you )
2
0
2k
Mar ’22
The application crashes in the App Store when launch on iPhone with iOS 15.3.1.
My application is currently crashing in production in iPhone devices running iOS 15.x. The app will work as normal while running developer mode, enterprise builds and Test Flight builds. Unfortunately, I am unable to reproduce this issue even app is downloaded from the app store. I observed crash is happening at main.m. Can someone help me to reproduce this issue? How to read this crash log file? Please find the crash log details attached. 2022-03-04_14-15-23.6227_+0900-a1899fd803a4ed683466702be71b9d224b4cd5bc.crash
3
1
3.2k
Mar ’22
What is "focus"?
In iOS 15 SDK you added the new FocusState API in SwiftUI. However there is no discussion or explanation anywhere that I could find, which explains: What exactly is "focus"? What isn't focus? What is the relationship between FocusState and accessibility focus? What is the relationship between whether a SecureField is being edited, and whether it's "focused"? Example: Lets say my tvOS app has an on-screen keyboard, where the user uses the remote's directional controls to move focus around to the letter buttons. To enter their password, they focus the password field, then click the center button to activate it. Now that it's active, they move focus to each letter of their password and click on each one: P... A... S... S... W... R... D... !... then they move focus to the "Submit" button and click. In this case, while the SecureField is being edited, focus moves around to a bunch of different buttons. The point of this example is that, if SecureField had a public "isBeingEdited" property, then it would be TRUE even while the field is not focused. However most Workday's designers interpret "focused" as being totally equivalent to "isBeingEdited" because in a web browser, tabbing out of a field makes it stop being edited. What is Apple's intent here? When not using a remote or physical keyboard or screen-reader, how is focus supposed to relate to whether a field is being edited? Does this relationship change when a user now has a bluetooth keyboard connected and Full Keyboard Access is turned ON? How does this correlate with accessibility focus? I cannot find any documentation from Apple that explains what focus is, or how this is supposed to work in SwiftUI in the various different scenarios where the concept of "focus" is relevant. Do you have a link to something current that explains how it's supposed to work so that we will know if there's a bug? Last question: how can we make the iOS simulator treat the physical keyboard as if it was a bluetooth keyboard to be used for focus-based keyboard navigation?
5
0
2.1k
Apr ’22
SwiftUI Settings scene (Preferences): how call action when closed by user (click on red button or Cmd-W)
Hi, I thought this should be quite easy and maybe I only have tomatoes on my eyes, but I cannot find out how to call an action when the user clicks the red button or use CMD-W to close the Preferences window (= Settings Scene). I use Core Data. In the Preferences, many data structures, which define my system, are changed. I learned, that you shouldn't save too often to avoid performance problems, so now I want to save the Core Data context when the user closes the Preferences window. I tried .onDisappear, onChange of focus etc. but this didn't work. How can I define an action? Any hints are welcome :-)
2
0
1.4k
Apr ’22
FamilyActivityPicker selection seems different from OS
Hi, I've implemented the FamilyActivityPicker and I also noticed that it is the same picker that we get when we go to Setttings > Screen Time > App Limits > Add Limit. When you tap on a given row, it will present all apps that are in that category. If you press the check mark on Category then on the Category row will be updated by showing the checkmark as selected and a "All" text to the right side, and on the app rows from that category the check marks will also be marked as selected. This behavior is not consistent when I implement the FamilyActivityPicker. If I go through the same process the app rows won't be shown as selected. Any suggestions on how to make this work? I'm attaching screen shots to illustrate my point. Settings App My FamilyActivityPicker Implementation
1
1
792
May ’22
Device Activity Framework iPhone , iPad
Hi dear , I am a beginner developer I have an application idea , and I think its great idea 😎 I think the application needs to use Device activity frame work , and UIScreen class , even if the app is in background or terminated , the problem is I don't know how to use these classes and frameworks 🤷🏻‍♂️ the questions are : can I detect UITouch event on UIScreen object even if the app is in background or terminated How to get the current activity name of the device
1
0
942
May ’22
Quick Look Preview Extension
I'm trying to add a quick look preview extension to my app. But I can't find any reference on this On a earlier thread (https://developer.apple.com/forums/thread/704155) everyone seems to misunderstand my question. I MEAN THE QUICK LOOK YOU CAN TOGGLE IN FINDER THAT WILL SHOW YOU A PREVIEW OF A DOCUEMNT I don't want to add the tag QuickLook because that's not I want to do.
1
0
595
May ’22
SwiftUI List selection bug
Is there a way to optimize a List in SwiftUI? There is a problem with selection not working properly when the List has many rows. If you scroll to multi-select and up, some rows in the middle are not selected. I have an issue where selecting an unselected row deselects nearby rows. Is there any way for selection to work reliably even for a List of many rows? I would like to find a solution that is stable even when multiple lines are selected, like mail and note, which are the default apps in ios. ps. I am using CoreData. @State var selectedItem = Set<MyEntity>() List(selection: $selectItem){   ForEach(items, id: \.self){ item in     ContactsRow(contactsData: item)   } } .environment(\.editMode, $editMode)
1
0
1.6k
Jun ’22
Drag and Drop using SwiftUI
Overview I am bit confused regarding drag and drop on SwiftUI I think there are 2 approaches but I am stuck with both approaches WWDC22 When using the new draggable, dropDestination, Transferable API, only single items are draggable. Multiple items in a list are not draggable. I have filed a feedback FB10128110 WWDC21 I have faced a couple of issues for drag and drop introduced in WWDC21 (onDrag, onDrop, itemIdentifier), the Feedback ids are FB9854301, FB9854569, FB9855245, FB9855532, FB9855567, FB9855575. It contains sample projects, would really appreciate if someone could have a look it. Note: All feedbacks include a sample project with detail steps and some even have screenshots and videos Questions: If my approach is wrong or if I am missing something? Unfortunately I didn't manage to get a SwiftUI lab session (got cancelled), so please help me with these issues.
4
1
3.3k
Jun ’22
Navigation: update multiple times per frame
After updating to NavigationStack with nested navigation links (with navigation links in a navigation destination), I see a lot of warnings in Xcode 14 beta: Update NavigationAuthority bound path tried to update multiple times per frame. Update NavigationAuthority possible destinations tried to update multiple times per frame. The app often freezes when navigated with a NavigationLink. Do others see these problems?
24
17
17k
Jun ’22
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.4k
Jun ’22
SwiftUI Scrollview with both axes enabled produces layout mess
The Problem In our brand new SwiftUI project (Multiplatform app for iPhone, iPad and Mac) we are using a ScrollView with both .horizontal and .vertical axes enabled. In the end it all looks like a spreadsheet. Inside of ScrollView we are using LazyVStack with pinnedViews: [.sectionHeaders, .sectionFooters]. All Footer, Header and the content cells are wrapped into a LazyHStack each. The lazy stacks are needed due to performance reasones when rows and columns are growing. And this exactly seems to be the problem. ScrollView produces a real layout mess when scrolling in both axes at the same time. Tested Remedies I tried several workarounds with no success. We built our own lazy loading horizontal stack view which shows only the cells whose indexes are in the visible frame of the scrollview, and which sets dynamic calculated leading and trailing padding. I tried the Introspect for SwiftUI packacke to set usesPredominantAxisScrolling for macOS and isDirectionalLockEnabled for iOS. None of this works as expected. I also tried a workaround to manually lock one axis when the other one is scrolling. This works fine on iOS but it doesn't on macOS due to extreme poor performance (I think it's caused by the missing NSScrollViewDelegate and scroll events are being propagated via NotificationCenter). Example Screen Recordings To give you a better idea of what I mean, I have screenshots for both iOS and macOS. Example Code And this is the sample code used for the screenshots. So you can just create a new Multiplatform project and paste the code below in the ContentView.swift file. That's all. import SwiftUI let numberOfColums: Int = 150 let numberOfRows: Int = 350 struct ContentView: View { var items: [[Item]] = { var items: [[Item]] = [[]] for rowIndex in 0..<numberOfRows { var row: [Item] = [] for columnIndex in 0..<numberOfColums { row.append(Item(column: columnIndex, row: rowIndex)) } items.append(row) } return items }() var body: some View { Group { ScrollView([.horizontal, .vertical]) { LazyVStack(alignment: .leading, spacing: 1, pinnedViews: [.sectionHeaders, .sectionFooters]) { Section(header: Header()) { ForEach(0..<items.count, id: \.self) { rowIndex in let row = items[rowIndex] LazyHStack(spacing: 1) { ForEach(0..<row.count, id: \.self) { columnIndex in Text("\(columnIndex):\(rowIndex)") .frame(width: 100) .padding() .background(Color.gray.opacity(0.2)) } } } } } } .edgesIgnoringSafeArea([.top]) } .padding(.top, 1) } } struct Header: View { var body: some View { LazyHStack(spacing: 1) { ForEach(0..<numberOfColums, id: \.self) { idx in Text("Col \(idx)") .frame(width: 100) .padding() .background(Color.gray) } Spacer() } } } struct Item: Hashable { let id: String = UUID().uuidString var column: Int var row: Int } Can You Help? Okay, long story short... Does anybody knows a real working solution for this issue? Is it a known SwiftUI ScrollView bug? If there were a way to lock one scrolling direction while the other is scrolled, then I could deal with that. But at the moment, unfortunately, it is not usable for us. So any solution is highly appreciated! Ideally an Apple engineer can help. 😃 NOTE: Unfortunately Apple does not allow URLs to anywhere. I also have two screen recordings for both iOS and macOS. So, if you would like to watch them, please contact me.
5
3
4.6k
Jun ’22
Storyboard target in Beta
I am currently running Xcode Version 14.0 beta (14A5228q) creating a Multiplatform app. I wanted to include a LaunchScreen so added a Launch Screen Storyboard to my project. To the the app to see it I went under Target for my app, General, and under App Icons and Launch Screen I set the Launch Screen File to my storyboard. This works perfectly when I run the app on iOS; however, when I run it on macOS I get an error:Launch Screen.storyboard error build: iOS storyboards do not support target device type "Mac". I see there's no way to differentiate between macOS and iOS with the file and there's only one target. Does anyone know a way to make the storyboard only launch when running the iOS app (and iPadOS) and not be seen when running macOS? Thanks
2
0
1.5k
Jul ’22
Swift charts displaying wrong theme through UIHostingController
Hi there, I'm currently using UIHostingController to display swift charts in uikit. The problem im facing is that the UIHostingController isn't outputting the intended theme. When the simulator/phone is on dark mode the view is still in light mode. Iv'e tried to force the view to use dark mode with: .environment(\.colorScheme, .dark) But it doesn't seem to help. Here's how I implement the UIHostingController to my view: let controller = UIHostingController(rootView: StatVC()) controller.view.translatesAutoresizingMaksIntoConstraints = false addChild(controller) controller.didMove(toParent: self) view.addSubview(controller.view) where StatVC() is the swiftui view which contains the swift chart.
1
0
1.1k
Jul ’22
SwiftUI: Bottom sheet from the iPhone "find my" and "maps" app
I would like to include the bottom sheet from the iPhone "find my" and "maps" app in my app. During my research I came across the new modifier .presentationDetents for sheets. The only problem here is that you can no longer interact with the main screen when the sheet is active. In my app, however, I would like the sheet to be active all the time like in the iPhone apps mentioned and that you can still interact with the main screen like in the iPhone apps with the map. I would be very happy about help. Greetings
10
4
4.8k
Aug ’22
"UI unresponsiveness" warning on @main
I'm seeing a runtime warning in Xcode 14 Beta 5 that says "This method should not be called on the main thread as it may lead to UI unresponsiveness." This is happening on the @main entry point of my app. See below: The warning shown gives me no insight into what's actually going wrong. I think it may be due to some Core Location code that runs when the app first opens, but is there a way for me to get some more insight into what's causing this? Or is this possibly an Xcode 14/iOS 16 bug, and this is not an issue to worry about? I'm not getting any warnings on Xcode 13/iOS 15.
75
27
77k
Aug ’22
SwiftUI: Conditionally switching between .fullScreenCover() and .sheet() not working
I'd like to use .fullScreenCover() or .sheet() to present a View, depending on the current horizontalSizeClass. If starting the following code in an iPhone (in portrait mode = .compact) or in an iPad (= .regular), the View is correctly displayed in a Sheet (iPhone) or in a FullScreenCover (iPad). However when using SplitScreen mode on an iPad (and thus switching between .compact and .regular the View remains in the container it was originally displayed. How can I correctly update this when switching between sizes on-the-fly? struct ContentView: View {     @Environment(\.horizontalSizeClass) var horizontalSizeClass     var body: some View {         Group {             Text("hidden behind modal")         }         .modal(isPresented: .constant(true)) {             if horizontalSizeClass == .regular {                 Rectangle()                     .fill(Color.red)                     .edgesIgnoringSafeArea(.all)             } else {                 Rectangle()                     .fill(Color.blue)                     .edgesIgnoringSafeArea(.all)             }         }     } } struct Modal<ModalContent: View>: ViewModifier {     @Environment(\.horizontalSizeClass) var horizontalSizeClass     @Binding var isPresented: Bool     @ViewBuilder let modalContent: ModalContent     func body(content: Content) -> some View {         if horizontalSizeClass == .regular {             content                 .fullScreenCover(isPresented: $isPresented) {                     modalContent                         .overlay {                             Text("horizontalSizeClass: regular")                         }                 }         } else {             content                 .sheet(isPresented: $isPresented) {                     modalContent                         .overlay {                             Text("horizontalSizeClass: compact")                         }                 }         }     } } extension View {     public func modal<Content: View>(isPresented: Binding<Bool>, @ViewBuilder content: @escaping () -> Content) -> some View {         modifier(Modal(isPresented: isPresented, modalContent: content))     } }
1
0
702
Aug ’22
Adopt UIFindInteraction across multiple views
We are currently trying to adopt the newly introduced find bar in our app. The app: The app is a text editor with a main text view. However it includes nested views (for text like footnotes) that are presented as modal sheets. So you tap on the footnote within the main text, a form sheet is presented with the contents of the footnote ready to be edited. We have an existing search implementation, but are eager to move to the system-provided UI. Connecting the find bar through a custom UIFindSession with our existing implementation is working without any issues. The Problem: Searching for text does not only work in the main text view, but also nested text (like footnotes). Let's say I have a text containing the word "iPhone" both in the main text and the footnote. In our existing implementation, stepping from the search match to the next one would open the modal and highlight the match in the nested text. The keyboard would stay open. With the new UIFindInteraction this is not working however. As soon as a modal form sheet is presented, the find interaction closes. By looking at the stack trace I can see a private class called UIInputWindowController that cleans up input accessory views after the modal gets presented. I believe it is causing the find panel to give up its first responder state. I noticed that opening popovers appears to be working fine. Is there a way to alter the presentation of the nested text so that the view is either not modal or able to preserve the current find session? Or is this unsupported behavior and we should try and look for a different way? The thing that really confuses me is that this appears to work without issue in Notes.app. There the find bar is implemented as well. There are multiple views that can be presented while the find bar is open. Move Note is one of them. The view appears as a modal sheet. It keeps the find bar open and active, though its tint color matches the deactivated one of the main Notes view. The find bar is still functional with the text field being active and the overlay updating in the background. This behavior appears to be a bug in the Notes app, but is exactly what we want for our use case. I attached some images: Two are from the Notes app, two from a test project demonstrating the problem. Opening a modal view closes the find bar there.
2
0
1.2k
Aug ’22
UIDocumentPickerViewController -> OneDrive/G-Drive -> NSFileCoordinator
Hey, I'm not sure I'm even in the correct ballpark - trying to allow my app to download largish videos from user's OneDrive and G-Drive to app Is it correct to use NSFileCoordinator in this way? How do I report progress as it downloads the video (is it possible?) Is it correct to dismiss the picker like this? anything else wrong (or, like is....any of it correct? :) it's sort of working with my contrived examples (I created new personal G-drive / Onedrive accounts, and copied vids up there), but...when I use a file from our corporate OneDrive, from shared folder, I get: "NSCocoaErrorDomain Code=3328 "The requested operation couldn’t be completed because the feature is not supported." Is this the NSFileProvider extension (Microsoft's) complaining? public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {     guard  let url = urls.first else {       return     }     let isSecurityScoped = url.startAccessingSecurityScopedResource()     print("(#function) - iSecurityScoped = (isSecurityScoped)")     print("(#function) - document at (url)")     let filename = String(UUID().uuidString.suffix(6)) + "_" +  url.lastPathComponent     let newURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent(filename)          let readingIntent = NSFileAccessIntent.readingIntent(with: url, options: .withoutChanges)     fileCoordinator.coordinate(with: [readingIntent], queue: queue) { error in       defer {         if isSecurityScoped {           url.stopAccessingSecurityScopedResource()         }       }       if let error = error {         print("(#function) - (error)")         return       }       let safeURL = readingIntent.url       do {         let fileData = try Data(contentsOf: safeURL)         try fileData.write(to: newURL, options: .atomic)         print("(#function) - SUCCESS - newURL = (newURL)")       } catch {         print("(#function) - NOOOOO - (error)")       }     }     controller.dismiss(animated: true)   }
1
1
971
Aug ’22