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

UIKit Documentation

Post

Replies

Boosts

Views

Activity

UITextView changed sequence of views in iOS 18
UITextView changed the sequence of views and on the top UIView. As a result in the custom gesture class in "touchesBegan" method, this code brings me "let touchedView = touches.first?.view" type of view UIView but it must be my own custom class type. How can I get a tapped type of view? Help please override func touchesBegan(_ touches: Set, with event: UIEvent) { super.touchesBegan(touches, with: event) let touchedView = touches.first?.view }
1
0
178
Sep ’24
What is ChronoKit.InteractiveWidgetActionRunner.Errors Code 1?
This is a follow up to this post about building a Control Center widget to open the app directly to a particular feature. I have it working in a sample app, but when I do the same thing in my full app I get this error: [[com.olivetree.BR-Free::com.olivetree.BR-Free.VerseWidget:com.olivetree.BR-Free.ContinueReadingPlanControl:-]] Control action: failed with error: Error Domain=ChronoKit.InteractiveWidgetActionRunner.Errors Code=1 "(null)" Google has nothing for any of that. Can anyone shed light on what it means? This is my control and its action: @available(iOS 18.0, *) struct ContinueReadingPlanControl : ControlWidget { var body: some ControlWidgetConfiguration { StaticControlConfiguration(kind: "com.olivetree.BR-Free.ContinueReadingPlanControl") { ControlWidgetButton(action: ContinueReadingPlanIntent()) { Image(systemName: "book") } } .displayName("Continue Reading Plan") } } @available(iOS 18.0, *) struct ContinueReadingPlanIntent : ControlConfigurationIntent { static let title: LocalizedStringResource = "Continue Reading Plan" static let description = IntentDescription(stringLiteral: "Continue the last-used reading plan") static let isDiscoverable = false static let opensAppWhenRun: Bool = true @MainActor func perform() async throws -> some IntentResult & OpensIntent { let strUrl = "olivetree://startplanday" UserDefaults.standard.setValue(strUrl, forKey: "StartupUrl") return .result(opensIntent: OpenURLIntent(URL(string: strUrl)!)) } } Note also that I'm pulling this from Console.app, streaming the logs from my device. I don't know of a way to debug a Control Center widget in Xcode, though this thread implies that it's possible.
2
0
448
Sep ’24
This is an internal UIKit bug. Ignoring unexpected nonmatching counterpart: (null)
FB14569448 Since iOS 18 beta came out, our app has been failing at some point when a view controller is dismissed and it appears the main thread ends up looping in layout logic and logs the following to the console. The app hangs until it's terminated due to a memory overallocation issue. Anyone else seen this? <_UINavigationBarItemStackEntry: 0x302ac73f0> normalLayout[active]=0x1391ad880 searchLayout=0x0 item=<UINavigationItem: 0x13913a080> style=navigator: Ignoring unexpected nonmatching counterpart: (null) This is an internal UIKit bug. Snapshotting a view (0x1391e7c00, _UIButtonBarStackView) that has not been rendered at least once requires afterScreenUpdates:YES. frame #0: 0x000000019bb07000 libobjc.A.dylibobjc_msgSend frame #1: 0x00000001a0fb4224 UIKitCore-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 144 frame #2: 0x00000001c270a030 CoreAutoLayout-[NSISEngine withBehaviors:performModifications:] + 84 frame #3: 0x00000001a0fe5424 UIKitCore__100-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke + 120 frame #4: 0x00000001a0fe3ae0 UIKitCore-[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 112 frame #5: 0x00000001a0fe2b4c UIKitCore-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 172 frame #6: 0x00000001a0fa9e90 UIKitCore-[UIView _updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:] + 400 frame #7: 0x00000001a0fa9a18 UIKitCore-[UIView _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 312 frame #8: 0x00000001a0fa97a4 UIKitCore-[UIView(Hierarchy) layoutSubviews] + 204 frame #9: 0x00000001a124fa78 UIKitCore-[_UIButtonBarStackView layoutSubviews] + 56 frame #10: 0x00000001a0f6430c UIKitCore-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2492 frame #11: 0x00000001a029d8d0 QuartzCoreCA::Layer::layout_if_needed(CA::Transaction*) + 496 frame #12: 0x00000001a0fa81d0 UIKitCore-[UIView(Hierarchy) layoutBelowIfNeeded] + 300 frame #13: 0x00000001a1843fa4 UIKitCore-[_UINavigationBarTransitionContextCrossfade _prepareContentView] + 132 frame #14: 0x00000001a18443bc UIKitCore-[_UINavigationBarTransitionContextCrossfade prepare] + 84 frame #15: 0x00000001a184e59c UIKitCore-[_UINavigationBarVisualProviderModernIOS _performAnimationWithTransitionCompletion:transition:] + 1524 frame #16: 0x00000001a180f938 UIKitCore-[UINavigationBar _popNavigationItemWithTransitionAssistant:] + 220 frame #17: 0x00000001a180f5f8 UIKitCore-[UINavigationBar _popNavigationItemWithTransition:] + 224 frame #18: 0x00000001a13bec9c UIKitCore-[UINavigationBar _setItemsUpToItem:transition:] + 240 frame #19: 0x00000001a13be76c UIKitCore-[UIViewController _removeNavigationItemsFromNavigationController:transition:] + 232 frame #20: 0x00000001a19c9dc0 UIKitCore__89-[UINavigationController _immediatelyApplyViewControllers:transition:animated:operation:]_block_invoke_3 + 800 frame #21: 0x00000001a19d0b2c UIKitCore__98-[UINavigationController _shouldSkipHostedRefreshControlUpdateSchedulingDeferredUpdateIfNecessary]_block_invoke + 40 frame #22: 0x00000001a19d7574 UIKitCore-[UINavigationController transitionConductor:didStartDeferredTransition:context:] + 792 frame #23: 0x00000001a21c9600 UIKitCore-[_UIViewControllerTransitionConductor startDeferredTransitionIfNeeded] + 688 frame #24: 0x00000001a10ab040 UIKitCore-[UINavigationController __viewWillLayoutSubviews] + 84 frame #25: 0x00000001a1350bcc UIKitCore-[UILayoutContainerView layoutSubviews] + 172 frame #26: 0x00000001a0f6430c UIKitCore-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2492 frame #27: 0x00000001a029d8d0 QuartzCoreCA::Layer::layout_if_needed(CA::Transaction*) + 496 frame #28: 0x00000001a029d45c QuartzCoreCA::Layer::layout_and_display_if_needed(CA::Transaction*) + 148 frame #29: 0x00000001a02f64e0 QuartzCoreCA::Context::commit_transaction(CA::Transaction*, double, double*) + 472 frame #30: 0x00000001a02736c4 QuartzCoreCA::Transaction::commit() + 648 frame #31: 0x00000001a02b6584 QuartzCoreCA::Transaction::flush_as_runloop_observer(bool) + 88 frame #32: 0x00000001a1002c3c UIKitCore_UIApplicationFlushCATransaction + 52 frame #33: 0x00000001a10002dc UIKitCore_UIUpdateSequenceRun + 84 frame #34: 0x00000001a0ffff2c UIKitCoreschedulerStepScheduledMainSection + 172 frame #35: 0x00000001a1000df0 UIKitCorerunloopSourceCallback + 92 frame #36: 0x000000019e7edf90 CoreFoundation__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 frame #37: 0x000000019e7edf24 CoreFoundation__CFRunLoopDoSource0 + 176 frame #38: 0x000000019e7eba10 CoreFoundation__CFRunLoopDoSources0 + 244 frame #39: 0x000000019e7eac14 CoreFoundation__CFRunLoopRun + 840 frame #40: 0x000000019e7ea4c8 CoreFoundationCFRunLoopRunSpecific + 572 frame #41: 0x00000001eb06d1c4 GraphicsServicesGSEventRunModal + 164 frame #42: 0x00000001a1334a90 UIKitCore-[UIApplication _run] + 816 frame #43: 0x00000001a13e2d1c UIKitCoreUIApplicationMain + 340 frame #44: 0x000000010038ca7c LabWare Developmentmain at AppDelegate.swift:31:7 frame #45: 0x00000001c4f4e9b4 dyldstart + 2724
2
0
440
Aug ’24
UIKit in SwiftUI memory leak while displaying images
I'm using UIKit to display a long list of large images inside a SwiftUI ScrollView and LazyHStack using UIViewControllerRepresentable. When an image is loaded, I'm using SDWebImage to load the image from the disk. As the user navigates through the list and continues to load more images, more memory is used and is never cleared, even as the images are unloaded by the LazyHStack. Eventually, the app reaches the memory limit and crashes. This issue persists if I load the image with UIImage(contentsOfFile: ...) instead of SDWebImage. How can I free the memory used by UIImage when the view is removed? ScrollView(.horizontal, showsIndicators: false) { LazyHStack(spacing: 16) { ForEach(allItems) { item in TestImageDisplayRepresentable(item: item) .frame(width: geometry.size.width, height: geometry.size.height) .id(item.id) } } .scrollTargetLayout() } import UIKit import SwiftUI import SDWebImage class TestImageDisplay: UIViewController { var item: TestItem init(item: TestItem) { self.item = item super.init(nibName: nil, bundle: nil) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewDidLoad() { super.viewDidLoad() let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) imageView.center = view.center view.addSubview(imageView) imageView.sd_setImage(with: item.imageURL, placeholder: nil) } } struct TestImageDisplayRepresentable: UIViewControllerRepresentable { var item: TestItem func makeUIViewController(context: Context) -> TestImageDisplay { return TestImageDisplay(item: item) } func updateUIViewController(_ uiViewController: TestImageDisplay, context: Context) { uiViewController.item = item } }
0
0
299
Sep ’24
iOS 18 rotate animation not working by layer for custom icon
I have created a custom logo in the SFSymbols 6.1 app and exported it as SVG. clock.arrow.trianglehead.clockwise.rotate.90.svg The icon consists of two layers and I want them to animate by layer. This works for the wiggle effect (the two layers are moving independently), but not for the rotate effect (the logo moves as a whole). Why? This is my code: let imageView = UIImageView() imageView.preferredSymbolConfiguration = UIImage.SymbolConfiguration(scale: .large) imageView.image = UIImage(named: "clock.arrow.trianglehead.clockwise.rotate.90", in: nil, with: nil) imageView.translatesAutoresizingMaskIntoConstraints = false let imageView2 = UIImageView() imageView2.preferredSymbolConfiguration = UIImage.SymbolConfiguration(scale: .large) imageView2.image = UIImage(named: "clock.arrow.trianglehead.clockwise.rotate.90", in: nil, with: nil) imageView2.translatesAutoresizingMaskIntoConstraints = false imageView.addSymbolEffect(.rotate.byLayer, options: .repeat(.continuous)); imageView2.addSymbolEffect(.wiggle.byLayer, options: .repeat(.continuous)); view.addSubview(imageView) view.addSubview(imageView2) NSLayoutConstraint.activate([ imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor), imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor), imageView2.centerXAnchor.constraint(equalTo: view.centerXAnchor), imageView2.topAnchor.constraint(equalTo: imageView.bottomAnchor, constant: 40), ])
2
0
359
Sep ’24
iOS 18 navigationbar UI bug
In iOS 18, when navigating from Page A (with a red navigation bar background color) to Page B, and Page B hides the navigation bar, upon returning to Page A, the background color of the navigation bar appears white (seemingly transparent). The navigation bar background for the share button should be red.
0
1
322
Sep ’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
6
8
1.5k
Jun ’24
Watch OS11 My recording play gets paused after a while
Watch OS11 My recording play gets paused when watch I turned down. It was not happening in previous versions. In my app I recorded my recording. And When I play it in my app, it was playing good in debug mode(when Xcode is connected) could not debug. Otherwise, it was automatically paused(when my wrist is down or inactivity time is elapsed) I want it to be continued.
1
0
326
Sep ’24
Issues with Handling URL Schemes and App State Transitions in iOS App
I'm working on an iOS app that integrates with Spotify for authentication. I’m facing a problem where the app doesn’t handle URL schemes and app state transitions properly. Specifically, when Spotify redirects back to my app, it either doesn’t handle the URL correctly or doesn’t transition between states as expected. The authorization for spotify is successful, then my app reopens and nothing happens after that. Expected Behavior: When Spotify redirects to my app, it should correctly handle the URL and process authentication parameters. Actual Behavior: Even with URL handling code commented out, the app reopens from Spotify, which suggests a possible issue with how URL schemes or app state transitions are managed. The app’s state transitions don’t seem to be handled as expected. Troubleshooting Steps Taken: Verified URL schemes and redirect URIs. Implemented application(_:open:options:) for URL handling. Tested various app states (foreground, background, suspended). //This code should open my app using the URL from spotify but this code never triggers and yet my app opens anyways// func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { print("Received URL: (url.absoluteString)") handleSpotifyURL(url) return true } private func handleSpotifyURL(_ url: URL) { // URL handling logic } func applicationDidBecomeActive(_ application: UIApplication) { // Logic for when the app becomes active } //Using latest software for xcode, testing on iphone 14 with up to date software and up to date spotify As mentioned - have ensure that my info plist is configured correctly, that spotify authorizes correctly, that the redirect URI is correct in my code and on spotify for developers. From the testing I've done I imagine there is something wrong with how my app gets opened vs how it should get opened with the callback URL triggering func application(_ app: UIApplication, open url: URL, options:.... What I am expecting is that when spotify triggers the callback url - my app reopens with the above function and from there can retrieve the access token etc.
0
0
289
Sep ’24
show bugs in iOS 18
I used tabBarItem & UITabBarController create a demo app. then I set every pages backgroudcolor as red. when I change to every pages withing the tabBarItem at bottom. the page's background color highlight every time. I don't know why. Is this the new UIKit's bug?
2
0
281
Sep ’24
UI freezes during zooming action in UIScrollView
I implemented the view displaying the video on a UIScrollView, but the UI freezes during the zooming action. The clock and status bar both freeze, but interestingly, if I touch the tab bar, everything starts working again after a few seconds. I am experiencing this issue only on an iPhone 12 Pro running iOS 16.5.1, but it doesn’t occur on other phones. I would like to know if this is an OS bug. Has anyone else experienced the same issue?
0
0
110
Sep ’24
iOS18 Must appear crash bug
1、 hook respondsToSelector: 接口,比如 hook 后的接口名字为 yy_respondsToSelector: 2、在 yy_respondsToSelector 中使用传入的参数 aSelector。示例代码如下: (BOOL) yy_respondsToSelector:(SEL)aSelector { if ([self yy_respondsToSelector:aSelector]) { return YES; } if ([self.selectorNameArray containsObject:NSStringFromSelector(aSelector)]) { return YES; } return NO; } 2、在自定义 UIViewController,比如 YYViewController,实现下述代码 (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSMutableArray *vcs = [[NSMutableArray alloc]init]; [vcs addObject:[[UIViewController alloc] init] ]; [vcs addObject:[[UIViewController alloc] init] ]; self.navigationController.viewControllers = vcs; } 3、当页面 YYViewController加载并执行 viewDidAppear 时候, App 一定会出现崩溃,因为 aSelector 是一个非法指针,访问就会崩溃
1
0
229
Sep ’24
iOS18.0 and iOS18.1 will inevitably crash. - (BOOL) respondsToSelector:(SEL)aSelector aSelector may be invalid, resulting in a crash
Hook respondsToSelector: interface. For example, the name of the hooked interface is yy_respondsToSelector: 2. Use the passed parameter aSelector in yy_respondsToSelector. The sample code is as follows: (BOOL) yy_respondsToSelector:(SEL)aSelector { if ([self yy_respondsToSelector:aSelector]) { return YES; } if ([self.selectorNameArray containsObject:NSStringFromSelector(aSelector)]) { return YES; } return NO; } 2. In a custom UIViewController, such as YYViewController, implement the following code (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSMutableArray *vcs = [[NSMutableArray alloc]init]; [vcs addObject:[[UIViewController alloc] init] ]; [vcs addObject:[[UIViewController alloc] init] ]; self.navigationController.viewControllers = vcs; } 3. When the page YYViewController is loaded and viewDidAppear is executed, App There will definitely be a crash, because aSelector is an illegal pointer, and access will crash
0
0
210
Sep ’24
iOS18.0 及 iOS18.1 必现崩溃。- (BOOL) respondsToSelector:(SEL)aSelector 中 aSelector 可能无效,导致必现崩溃
1、 hook respondsToSelector: 接口,比如 hook 后的接口名字为 yy_respondsToSelector: 2、在 yy_respondsToSelector 中使用传入的参数 aSelector。示例代码如下: (BOOL) yy_respondsToSelector:(SEL)aSelector { if ([self yy_respondsToSelector:aSelector]) { return YES; } if ([self.selectorNameArray containsObject:NSStringFromSelector(aSelector)]) { return YES; } return NO; } 2、在自定义 UIViewController,比如 YYViewController,实现下述代码 (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSMutableArray *vcs = [[NSMutableArray alloc]init]; [vcs addObject:[[UIViewController alloc] init] ]; [vcs addObject:[[UIViewController alloc] init] ]; self.navigationController.viewControllers = vcs; } 3、当页面 YYViewController加载并执行 viewDidAppear 时候, App 一定会出现崩溃,因为 aSelector 是一个非法指针,访问就会崩溃
1
0
300
Sep ’24
Incorrect behaviour when trying to change focus to a focused view inside UIPageViewController
We are experiencing difficulties with keyboard navigation focus within a view contained inside a UIPageViewController. The intended keyboard navigation sequence does not function as expected. Expected Behavior: Pressing the Tab key once should move the focus to the UIPageViewController, allowing the use of the Up and Down arrow keys to navigate between pages. Pressing the Tab key a second time should shift the focus outside the UIPageViewController Pressing the Tab key a third time should move the focus back to the UIPageViewController. Actual Behavior: The focus does not shift as described above. Have sent a sample Xcode project to Apple demonstrating the issue (unfortunately it doesn't allow me to attach the zipped project here for some reason). STEPS TO REPRODUCE Set a breakpoint at viewDidAppear (line 44, MyViewController) Run the app, wait until it stops, and run the command in the lldb debugger Command: po UIFocusDebugger.checkFocusability(for: pager.viewControllers!.first!.view.subviews.first!) Output: The following issues were found that would prevent this item from being focusable: - ISSUE: One or more ancestors have issues that may be preventing this item from being focusable. Details: <_UIQueuingScrollView: 0x104826a00>: - ISSUE: This view returns YES from -canBecomeFocused, which will prevent its subviews from being focusable. <_UIPageViewControllerContentView: 0x103d07be0>: - ISSUE: This view returns YES from -canBecomeFocused, which will prevent its subviews from being focusable.
2
0
281
Sep ’24
Background Decoration View Overlapping Collection View Cells
I am encountering an issue with my UICollectionView layout where the background decoration view is overlapping the collection view cells. Below is the relevant code for my layout configuration: let itemSize = NSCollectionLayoutSize( widthDimension: .absolute(60), heightDimension: .absolute(100) ) let item = NSCollectionLayoutItem(layoutSize: itemSize) let groupSize = NSCollectionLayoutSize( widthDimension: .fractionalWidth(1), heightDimension: .absolute(100) ) let group = NSCollectionLayoutGroup.horizontal( layoutSize: groupSize, subitems: [item] ) let section = NSCollectionLayoutSection(group: group) section.decorationItems = [ NSCollectionLayoutDecorationItem.background(elementKind: "customBackgroundElementKind") ] return section Problem: The background decoration view is appearing on top of the collection view cells, which results in the cells being obscured. This issue is specific to iOS 18 and does not occur on iOS 17 and below. Request: Can anyone provide guidance or suggest a solution to ensure the decoration view does not overlap the collection view cells specifically on iOS 18? Thank you!
4
2
460
Sep ’24
How does OpenIntent in a control widget actually open the app to the target feature?
I want to add a Control Center widget for my app that will open the app to a particular feature. I'm looking at the "Open your app with a control" example here, which seems like exactly what I want: Set your control’s action to an app intent that conforms to OpenIntent to open your app when someone uses a control. Using OpenIntent allows you to take someone to a specific area of your app when a control performs its action. The example doesn't show exactly how to hook up the LaunchAppIntent to a control widget, but I'm guessing it's something like this: @available(iOS 18.0, *) struct OpenFeatureControl : ControlWidget { var body: some ControlWidgetConfiguration { StaticControlConfiguration(kind: "com.example.OpenFeature") { ControlWidgetButton(action: LaunchAppIntent()) { Image(systemName: "book") } } .displayName("Launch Feature") } } But there's one critical piece missing here: how is the target feature actually opened? My initial assumption would have been that once the app launches or resumes, there's a call to some method like continueUserActivity that has a user-info dict with some key whose value is the LaunchAppEnum. But I've put breakpoints on all those methods in my app and none of them get called (I'm using UIKit scene lifecycle). I also tried a regular AppIntent with a perform method that talks to my app directly: @available(iOS 18.0, *) struct OpenFeatureIntent : AppIntent { static let title: LocalizedStringResource = "Open My Feature" static let opensAppWhenRun: Bool = true init() {} func perform() async throws -> some IntentResult { //MAIN_APP is defined in Active Compilation Conditions in build settings #if MAIN_APP let url = URL(string: "myapp://openfeature")! UrlHandler.instance().handle(url) #endif return .result() } } But when run, this simply does nothing. Launching an app directly to a particular view or feature seems like a common use-case for control widgets, and there are apps doing it, but I can't find an example of how it's supposed to work. And the docs are really not helpful. Can anyone provide the missing piece here? What's the expected plumbing in an OpenIntent that actually launches particular UI in the app?
3
1
705
Sep ’24
UITabBarController render glitch since iOS18 beta 1 & 2 when activating tabs.
We have a UITabBarController in our iPhone App which has 5 tabs with UITableViewControllers (constructed from the storyboard). Before iOS18 beta 1 (and 2) this was working fine without any problems (objective-C). Since iOS18 beta 1 (and beta 2 still has this problem) a strange render glitch occurs when activating a tab from the tab bar at the bottom. As soon as a tab is activated (by tapping on the icon at the bottom) the tab with the UITableViewController becomes visible and draws its content starting at the very top of the screen (pos 0,0) right through/over the Navigation bar which at that point is showing a title and a rightBarButtonItem. The tab with the UITableViewController seems not aware there is a navigation bar visible. Then after ~0.3 seconds the tab with the UITableViewContoller is automatically rendered again or moved down and now its content starts below the UINavigationBar as expected, this is 100% reproducible and occurs on every activation of a tab in the UITabBarController. Is anyone else also getting this behavior in their App since iOS18? I'm aware that UITabBarController is being renewed but I can't find any information on why this behavior might occur. I was hoping beta 2 would solve the problem but it doesn't. Constructing the UITabBarController in the code with the new UITab objects (instead of constructing them from the storyboard) also shows this problem.
5
0
927
Jun ’24