Construct and manage graphical, event-driven user interfaces for iOS or tvOS apps using UIKit.

Posts under UIKit tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Navigation bar not shown in Supplementary view of a UISplitView in macOS Sonoma
I've run into a problem that has been giving me fits for a while and have yet to be able to find a solution. We have a Catalyst app that uses a three-pane UISplitView. The middle and third panes show the navigation bar of the UINavigationController hosted in each pane. However, when building under Xcode 15, the navigation bar is not shown in the middle pane when running under macOS 14. It is shown, as expected, when the app is run under prior versions of macOS. It also appears as it should under macOS 14 if the app is built with Xcode 14. If you push another view controller onto the navigation controller's stack with the animate flag set to true, the navigation bar will appear. When you go back to the root controller, the navigation bar is present as it should be. However, if you push the controller with the animate flag set to false, the navigation bar does not appear. I've been able to reproduce this in an isolated test app with just the relevant components. The first screenshot at the end is from a test app that illustrates the problem. The second screenshot shows what it should look like (and does look like under macOS 13). It should be noted that UINavigationBar.appearance().preferredBehavioralStyle = .pad is set. If any Apple folk would kindly like to look into this, I created a feedback for it: FB13260893. The feedback entry has a sample app, screenshots, and even a screen recording demonstrating the problem. Has anyone else run into this or does anyone have any suggestions for a fix/workaround? Thanks, Kevin
2
1
524
Jun ’24
Using Genmoji with local notifications
As per subject. Is this possible at all? The WWDC video only talks about the communication / push notifications. There doesn't seem to be any update to UNNotificationContent to allow setting of attributed strings. If your app makes use of communication notifications you can even include Genmoji and other image glyphs in your notifications with the new "UNNotificationAttributed MessageContext API". For push notifications, the payload just needs to contain a rich text representation that may contain image glyphs. We recommend that you use a Notification Service Extension to parse the rich text, download assets, create the attributed body and update the notification content
1
0
221
Jun ’24
Pre-rendering WKWebView to avoid flashing
Has anyone attempted to render a WKWebView in a background or invisible UIView so that it’s visible immediately upon first presentation, and if so, what technique did you use? Background: We are trying to embed a WKWebView in our UI that renders seamlessly next to native UI. We are going to download a .ZIP file, unzip it locally to disk, and then point the WKWebView to that local file. However, when testing this solution on an iOS simulator (running iOS 17.5), we see a flash of white – specifically there is no content rendered for the first moment or two, followed by content appearing. We have tried attaching the WKWebView to the UIWindow, adding a javascript callback for the onReadyStateChange “loaded” event, and then only proceeding to present our UIViewController containing our WKWebView afterwards, but we still see a moment with no content being rendered at all. If we add a delay using DispatchQueue.asyncAfter of approximately one second (anything less still flashes), our content does seem to be correctly rendered in the background and immediately visible when the UIViewController gets presented. This is a problem that was originally asked nearly 11 years ago (https://stackoverflow.com/questions/15669809/how-to-prevent-initial-white-flash-when-showing-a-uiwebview); and the agreed upon solution there seems to be to set the background to be not opaque, but the issue remains that the content isn’t immediately visible. Google Gemini and ChatGPT have proposed a number of solutions, including hallucinations about headless WKWebView support on iOS, but unfortunately we are unable to achieve a solution without a DispatchQueue delay with a magic number.
0
0
229
Jun ’24
iOS 18 developer beta: Writing Tools
Based on the session content, it seems that setting the TextView property writingToolsBehavior = .complete should bring up the writing tools bottom panel view. However, it does not appear to be working. Is this a feature that will be added in a future update, or is there something additional I need to do? Test on: XCode 16.0 beta (16A5171c), iOS Simulator 18.0 Beta, iPhone 11 Pro iOS 18.0 Beta
4
6
420
Jun ’24
Why is KeyboardLayoutGuide not applied in viewIsAppearing() in iOS 15.0?
viewIsAppearing is available in iOS 13 and above, and I understand that setting the layout in this lifecycle is a good way to do it. But when I use it, confirmed that UIKeyboardLayout does not work properly in viewIsAppearing in iOS versions lower than 16.0. There is a small problem not only with viewIsAppearing, but also with viewDidLoad(). In viewDidLoad(), the component to which UIKeyboardLayoutGuide is applied is visible when the screen first appears. However, there is a problem where the layout with UIKeyboardLayoutGuide applied is not visible when returning after changing the navigation screen (Push & Pop). I confirmed that UIKeyboardLayoutGuide is applied properly in viewIsAppearing and viewDidLoad in iOS 16.0 and higher versions. Below is the code and environment for reproducing the problem situation. ==================================================== Envirionment: M1 Pro(Sonoma v14.5), Xcode(v15.4), iPhone Simulator (iOS v15.0, v15.2) import UIKit import SnapKit final class ViewController: UIViewController { private let uiTextField: UITextField = { $0.placeholder = "search" $0.backgroundColor = .red return $0 }(UITextField()) override func viewIsAppearing(_ animated: Bool) { super.viewIsAppearing(animated) view.backgroundColor = .white layout() } private func layout() { view.addSubview(uiTextField) uiTextField.snp.makeConstraints { $0.height.equalTo(50) $0.horizontalEdges.equalToSuperview() $0.bottom.equalTo(view.keyboardLayoutGuide.snp.top) } } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { view.endEditing(true) } } I wonder if I haven't checked what I need to check yet, or if there are other problems.
0
0
155
Jun ’24
iOS 17 - New status bar default style doesn't work if the status bar was previously hidden
Hi, I adopted in my app the new default style for the status bar where it switches between light and dark themes depending on the color of the content beneath. It works great until I hide the status bar and show it again. From that point onwards, the status bar will be stuck on the dark or light theme, depending on the app's theme. This happens as well if the status bar is initially hidden on startup. In that case, the default behavior never works. I filed an issue (FB13222217), and as of now I didn't find a workaround except never hiding the status bar on my app. I attached a super minimalist example project there, just a scroll view with black and white views and nothing more. This happens on SwiftUI and UIKit as well. I hope the issue can be addressed and will appreciate if anyone has a workaround for this to let me know. Thanks!
3
4
2.5k
Jun ’24
How to avoid Swift 6 concurrency warning from UIAccessibility.post()
I have the following var in an @Observable class: var displayResult: String { if let currentResult = currentResult, let decimalResult = Decimal(string: currentResult) { let result = decimalResult.formatForDisplay() UIAccessibility.post(notification: .announcement, argument: "Current result \(result)") return result } else { return "0" } } The UIAccessiblity.post gives me this warning: Reference to static property 'announcement' is not concurrency-safe because it involves shared mutable state; this is an error in Swift 6 How can I avoid this?
3
0
441
Jun ’24
Eye Tracking as a General API Feature for iPadOS 18+?
I'd like to use the eye tracking feature in the latest iPadOS 18 update as more than an accessibility feature. i.e. another input modality that can be detected by event + enum checks similar to how we can detect and distinguish between touches and Apple pencil inputs. This might make it a lot easier to control and interact with iPad-based AR experiences that involve walking around, regardless of whether eye-tracking is enabled for accessibility. When walking, it's challenging to hold the device and interact with the screen with touch or pencil at all. Eye tracking + speech as input modalities could assist here. Also, this would help us create non-immersive AR experiences that parallel visionOS experiences that use eye tracking. I propose an API option for enabling eye-tracking (and an optional calibration dialogue within-app), as well as a specific UIControl class that simply detect when the eye looks at the control using the standard (begin/changed/end) events. My specific use case is that I'd like to treat eye-tracking-enabled UI elements or game objects differently depending on whether something is looked at with the eyes. For example, to select game objects while using speech recognition, suppose we have 4 buttons with the same name in 4 corners of the screen. Call them "corner" buttons. If I have my proposed invisible UI element for gaze detection, I can create 4 large rectangular regions on the screen. Then if the user says "select the corner" the system could parse this command and disambiguate between the 4 corners by checking which of the rectangular regions I'm currently looking at. (Note: the idea would be to make the gaze regions rather large to compensate for error.) The above is just a simple example, but the advantage over other methods like dwell is that it could be a lot faster. Another simple example: Using the same rectangular regions, instead of speech input, I could hold a button placed in just one spot on the screen, and look around the screen with my gaze to produce a laser beam for some kind of game, or draw curves (that I might smooth-out to reduce inaccuracy). OR maybe someone who does not have their hands available. This would require us to have the ability to get the coordinates of the eye gaze, but otherwise the other approach of just opting to trigger uicontrol elements might work for coarse selection. Would other developers find this useful as well? I'd like to propose this feature in feedback assistant, but I'm also opening-up a little discussion if by chance someone sees this. In short, I propose: a formal eye-tracking API for iPadOS 18+ that allows for turning on/off the tracking within the app, with the necessary user permissions the API should produce begin/changed/ended events similar to the existing events in UIKit, including screen coordinates. There should be a way to identify that an event came from eye-tracking. alternatively, we should have at minimum an invisible UIControl subclass that can detect when the eyes enter/leave the region.
0
2
535
Jun ’24
UIPasteControl sometimes disappear
Problem Our app use UIPasteControl for people taps to place pasteboard contents in UITextView. It worked fine at first, but recently received a lot of user feedback and the button suddenly disappeared This problem usually occurs when an App switches between the front and back More Information When the button disappears, we find that the child view of the UIPasteControl control which name _UISlotView has a size of zero. we use UIKit and AutoLayout,limit button size (100, 36) let config = UIPasteControl.Configuration() config.displayMode = .labelOnly config.cornerStyle = .fixed config.baseForegroundColor = .white config.baseBackgroundColor = .black config.cornerRadius = 18 let btn = UIPasteControl(configuration: config) pasteBtn = btn addSubview(pasteBtn) pasteBtn.snp.makeConstraints { make in make.trailing.equalTo(-20) make.bottom.equalTo(-10) make.size.equalTo(CGSize(width: 100, height: 36)) } UI view information <UIPasteControl: 0x107dda810; frame = (0 0; 100 36); layer = <CALayer: 0x3010ff000>> (lldb) po [0x107dda810 subviews] <__NSSingleObjectArrayI 0x30152ff00>( <_UISlotView: 0x107dea630; frame = (0 0; 100 36); userInteractionEnabled = NO; layer = <CALayer: 0x3010eb460>> ) anyone meet before? is there a workaround?
2
0
215
Jun ’24
UIPrintPageRenderer hangs app after iPhone update
After updating iPhone from 17.4 to 17.5.1 UIPrintPageRenderer completely hangs app when getting NumberOfPages from Renderer. var render = new UIPrintPageRenderer(); if (webViewPages != null && reportIndex < webViewPages.Length) { render.AddPrintFormatter( webViewPages[reportIndex].ViewPrintFormatter, 0); } else { render.AddPrintFormatter( new UIMarkupTextPrintFormatter(reportContent), 0); } var printable = CoreGraphics.CGRectExtensions.Inset(page, 0, 0); render.SetValueForKey(NSValue.FromCGRect(page), new NSString("paperRect")); render.SetValueForKey(NSValue.FromCGRect(printable), new NSString("printableRect")); var pdfData = new NSMutableData(); UIGraphics.BeginPDFContext(pdfData, page, null); int pageNum = 0; for (pageNum = 0; pageNum < render.NumberOfPages; pageNum++) { UIGraphics.BeginPDFPage(); var bounds = UIGraphics.PDFContextBounds; render.DrawPage(pageNum, bounds); } UIGraphics.EndPDFContext();
0
1
199
Jun ’24
When using UIView.drawHierarchy, older CPU performs far better than newer CPU
Hi all, My app uses SpriteKit views which are rendered into images for various uses. For some reason, the same code performs worse on a newer CPU than on an older one. My A13 Bionic flies through the task at high resolution and 60FPS while CPU usage is <60%, while the A15 Bionic chokes and sputters at a lower resolution and 30FPS. Because of how counterintuitive this is, it took me a while to isolate the call directly responsible--with UIView.drawHierarchy commented out, both devices returned to their baseline performances. guard let sceneView = skScene.view else { return } let size = CGSize(width: outputResolution, height: outputResolution) return UIGraphicsImageRenderer(size: size).image { context in let rect = CGRect(origin: .zero, size: size) sceneView.drawHierarchy(in: rect, afterScreenUpdates: false) } Does anyone know why this is the case, and how to fix it? I tried using UIView.snapshotView, which is supposedly much faster, but it only returns blank images. Am I using it wrong or does it simply not work in this context? sceneView.snapshotView(afterScreenUpdates: false)?.draw(rect) Any hints or pointers would be greatly appreciated
0
0
187
Jun ’24
Crashed iOS app at CA::Transaction::commit()
Our on field app is facing significant crashes at CA::Transaction::commit() from QuartzCore. The crash report does not point to any code in our app and the information available is very limited. It's a EXC_BAD_ACCESS KERN_INVALID_ADDRESS crash. We have tried using sanitisers and zombies but unable to reproduce the crash locally. Can someone help explain and point in right direction? Below are the crash details. Full crash report Distributor ID: com.apple.AppStore Hardware Model: iPhone15,3 AppStoreTools: 15F31e AppVariant: 1:iPhone15,3:16 Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd [1] Date/Time: 2024-06-03 20:41:59.3315 +0530 Launch Time: 2024-06-03 19:15:20.6051 +0530 OS Version: iPhone OS 17.4.1 (21E236) Release Type: User Baseband Version: 2.51.04 Report Version: 104 Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000110 Exception Codes: 0x0000000000000001, 0x0000000000000110 VM Region Info: 0x110 is not in any region. Bytes before following region: 4372119280 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL UNUSED SPACE AT START ---> __TEXT 104994000-105420000 [ 10.5M] r-x/r-x SM=COW /var/containers/Bundle/Application/ Termination Reason: SIGNAL 11 Segmentation fault: 11 Terminating Process: exc handler [35195] Triggered by Thread: 0 Kernel Triage: VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter Thread 0 name: Thread 0 Crashed: 0 QuartzCore 0x000000018f4633b4 CA::Transaction::commit() + 1152 (CATransactionInternal.mm:480) 1 QuartzCore 0x000000018f4633ec CA::Transaction::commit() + 1208 (CATransactionInternal.mm:480) 2 QuartzCore 0x000000018f462e64 CA::Transaction::flush_as_runloop_observer(bool) + 88 (CATransactionInternal.mm:942) 3 UIKitCore 0x00000001900b1260 _UIApplicationFlushCATransaction + 52 (UIApplication.m:3160) 4 UIKitCore 0x00000001900b0d78 _UIUpdateSequenceRun + 84 (_UIUpdateSequence.mm:119) 5 UIKitCore 0x00000001900b0468 schedulerStepScheduledMainSection + 144 (_UIUpdateScheduler.m:1037) 6 UIKitCore 0x00000001900b0524 runloopSourceCallback + 92 (_UIUpdateScheduler.m:1186) 7 CoreFoundation 0x000000018ddc162c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:1957) 8 CoreFoundation 0x000000018ddc08a8 __CFRunLoopDoSource0 + 176 (CFRunLoop.c:2001) 9 CoreFoundation 0x000000018ddbf0b8 __CFRunLoopDoSources0 + 340 (CFRunLoop.c:2046) 10 CoreFoundation 0x000000018ddbdd88 __CFRunLoopRun + 828 (CFRunLoop.c:2955) 11 CoreFoundation 0x000000018ddbd968 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420) 12 GraphicsServices 0x00000001d20b34e0 GSEventRunModal + 164 (GSEvent.c:2196) 13 UIKitCore 0x0000000190230edc -[UIApplication _run] + 888 (UIApplication.m:3692) 14 UIKitCore 0x0000000190230518 UIApplicationMain + 340 (UIApplication.m:5282) 15 AppName 0x000000010542072c main + 64 (AppDelegate.swift:13) 16 dyld 0x00000001b12ded84 start + 2240 (dyldMain.cpp:1298)
0
0
193
Jun ’24
SwiftUI popover not respecting arrow direction
When I try to change the arrow direction for SwiftUI popover it's not working at all, but in UIKit it seems to be ok Please check the sample code Button { showPopover.toggle() } label: { Text("Show Popover") .padding(60) .border(Color.yellow) } .popover( isPresented: $showPopover, arrowEdge: .bottom // issue here ) { Text("Popover conent") }
2
0
199
Jun ’24
How to interact during the Transition process?(wwdc24 UIKit consultation)
Recently I tried to apply a custom transition to a custom contextMenu. However, I want to make sure that during the transition process (which is not over yet), my contextMenu elements such as buttons can be tapped. But I tried a lot of things without success. I know you have a lot of experience, so I would like to ask you about how to implement the transition and be able to interact before it is over. I know that a UIView can be tapped during animation, but I haven't tried the button in a UIView. I've been trying to transition ViewControllers. For example, in a transition from fromViewController to toViewController, I wanted to be able to tap on a tableView in toViewController during the transition, but I was frustrated and found it very difficult to implement. I would like to ask you about the possibilities of interaction during the Viewcontrollers transition. (PS: In Github Issues, I uploaded a GIF example of the plus button on the left of the input box in iMessage. After tapping the plus button, you can tap the "Apple Cash" button before the transition is finished.) Your advice would be incredibly valuable to me. Thank you in advance for your time and assistance. [GithubLink]https://github.com/Juhnkerg/DemoForInteractionDuringTransition)
0
1
258
Jun ’24
New Sliders
For the past couple of years, Apple has been using custom sliders in Music, Podcasts, and on the Lock Screen for scrubbing music and controlling volume. But those sliders are not available to 3rd party devs. We can recreate them theoretically for scrubbing audio. But not for volume, where in UIKit we are supposed to use MPVolumeView. Anyone from Apple? Are there any plans to make the slider styles used in Apple's audio apps available to the rest of us? FB12261162
0
0
201
Jun ’24
UIDevice: Main actor-isolated class property 'current' can not be referenced from a non-isolated context
I have a Safari Web Extension for visionOS that reads from UIDevice.current.systemVersion in order to provide the OS version number back to the JavaScript context utilizing beginRequest(with:). When switching my project to use Swift 6, I received this obscure error: Main actor-isolated class property 'current' can not be referenced from a non-isolated context Class property declared here (UIKit.UIDevice) Add '@MainActor' to make instance method 'beginRequest(with:)' part of global actor 'MainActor' Adding @MainActor causes another issue (Main actor-isolated instance method 'beginRequest(with:)' cannot be used to satisfy nonisolated protocol requirement) which suggests adding @preconcurrency to NSExtensionRequestHandling which then breaks at Non-sendable type 'NSExtensionContext' in parameter of the protocol requirement satisfied by main actor-isolated instance method 'beginRequest(with:)' cannot cross actor boundary. What's the proper solution here? Here's a simplified snippet of my code: class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling { func beginRequest(with context: NSExtensionContext) { // ... var systemVersionNumber = "" systemVersionNumber = UIDevice.current.systemVersion // ... } }
1
0
350
Jun ’24
Custom Domain deeplink
My SampleApp, named "myApp," already supports deep links such as "https://myApp.com/tab/record/10020." When this link is clicked, it navigates to myApp, and AppDelegate handles the further process. Now, I need to support another link (domain), "https://appcloud.com/tab/record/10020," so that clicking this link also navigates to myApp. Is there any way to solve this kind of problem without adding "apple-app-site-association"?
1
0
256
Jun ’24
UIKit ContactsAccessButton?
Apple revealed the ContactsAccessButton in the WWDC24 session 10121: Meet the Contact Access Button. After watching the video, reading through the documentation as well as the sample code , I can only find a SwiftUI ContactsAccessButton. However, our code base is written largely in UIKit, and our team prefers to do complex work and customization with lists via UITableView as opposed to SwiftUI List. So we would greatly prefer to use a UIKit ContactAccessButton. Is there not a UIKit equivalent to ContactsAccessButton? If there is, where can we find it?
1
0
270
Jun ’24