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

UIKit Documentation

Post

Replies

Boosts

Views

Activity

iOS 18 Translation API availability for UIKit
After reading the documentation for TranslationSession and other API methods I got an impression that it will not be possible to use the Translation API with UI elements built with UIKit. You don’t instantiate this class directly. Instead, you obtain an instance of it by adding a translationTask(_:action:) or translationTask(source:target:action:) function to the SwiftUI view containing the content you want to translate So the main question I have to the engineers of mentioned framework is will there be any support for UIKit or app developers will have to rewrite their apps in SwiftUI just to be able to use the Translation API?
1
1
368
2w
Text selection doesn't work in WKWebView on macOS Sonoma
Can not select anything within WkWebView editor view of my MacCatalyst app when running on macOS 14 Sonoma. Any selection gesture or command key fails to select anything in content editable WKWebView, so none of the Editor tools can be activated. My application uses the nnhubbard / ZSSRichTextEditor WKWebView-based Rich Text Editor: https://github.com/nnhubbard/ZSSRichTextEditor. The app is built with Xcode 15.4. The app is a Catalyst app that implements an editor view with a ZSSRichTextEditor WKWebView. The problem does not occur if the the app is run in macOS 11, 12, or 13 (Catalina, Monterey, or Ventura.) The issue only occurs in macOS 14 Sonoma. The following error message is logged whenever an attempt to select any text in the WKWebView content: 0x1359ecc18 - [pageProxyID=14, webPageID=15, PID=14,932] WebPageProxy::didFailProvisionalLoadForFrame: frameID=1, isMainFrame=1, domain=NSURLErrorDomain, code=18,446,744,073,709,550,614, isMainFrame=1, willInternallyHandleFailure=0 Without the ability to select text the editor (WKWebView) is useless since no editing tool can be invoked without a selection. An Apple Feedback report was filed: FB13344011. An incident was filed with DTS concerning this issue. Apple Developer Technical Support's reply was "Our engineers have reviewed your request and have determined that you are experiencing a known issue for which there is no known workaround at this time." Since DTS’ reply there has been no further response from them.
3
1
167
2w
Screen Sleep Issue When Removing Vision Pro
Hello VisionOS Developer Community, I am currently working on a demo application for VisionOS, tailored for the Vision Pro. In my application, I have implemented a feature to prevent the screen from sleeping using the following code: UIApplication.shared.isIdleTimerDisabled = true This works perfectly on iOS, ensuring the screen remains active regardless of other system settings. However, I've run into a snag with VisionOS. Even with isIdleTimerDisabled set to true, the screen still sleeps when I take off the Vision Pro.
0
0
124
2w
How on earth do I get the actual dimensions of a presented modal view on iPad?
This is the stupidest thing that should be so easy. I simply present a view controller using: [self presentViewController:settingsView animated:YES completion:^(){ }]; Then in the code for the view controller being presented, I want to know it's width, which should be stupidly simple using: const int viewWidth = self.view.frame.size.width; HOWEVER, this gives me a value that is the same as the parent view's width, yet on iPad at least this view is visibly smaller than the parent/presenting view (as it is hovering over it with the view visible around the edges behind it). I have tried every stupid thing I can find within the parent view and view controller code that mentions margins and insets and whatnot, but nothing seems to give me the actual stupid value of the stupid presented view's visible dimensions! Any ideas? The iPad is on iPadOS 15.3.1, might try installing a newer version and see if this is some bug in this particular version of the OS.
4
0
206
2w
UITextView with large `textContainerInset` scrolls upwards when selecting text
Whenever a UITextView has a large textContainerInset it starts scrolling upwards rapidly when selecting text. For my use case, I have a custom view that I display in the text view to show the comment you are writing a reply to. To accomplish this, I use the textContainerInset and set the top portion of that inset to a large value. Here is a video showing the issue: https://streamable.com/9z57ok I've also made a very simple sample project to demonstrate and here is the main view controller code: https://gist.github.com/rickharrison/9cf563bcb22130bfafc7d3b5d37c55f2 Is it possible to disable scrolling of the UITextView while the selection UI is shown? Or is there another way I should inset the text to edit? I found another thread with this issue from years ago, but no solution - https://developer.apple.com/forums/thread/129882
3
0
209
Jun ’24
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
680
May ’22
UIDocumentViewController based app built for iOS 17.5 unexpectedly uses new document launch experience under iOS 18 developer beta
In the WWDC24 session Evolve your document launch experience, it is mentioned that apps linked against the iOS 17 SDK would not get the new document launch experience. However, I found that the new document browser is active in my iOS 17 app when installed from the App Store on iOS 18, without rebuilding it. This (along with other iOS 18 UIKit behavioral regressions) renders the app unusable when running under iOS 18. To be clear, my app uses a UIDocumentViewController as the root view controller of a UINavigationController and is implemented primarily in Obj-C. I don't want to show the new document browser to users at app launch time. The current behavior of my app is that it always launches to either the current document or a new document and then allows the user to open a new document using the document picker if desired (this was accomplished by invoking the action associated with the Documents button on iOS 17; see related feedback FB13418866: ER: UIDocumentViewController should provide API to allow customization of Documents button behavior). The new UIDocumentViewController behavior is problematic because it has replaced the Documents button with a backAction that moves the user into the new document browser with no way to back out, aside from picking a document or creating a new document. Previously, the user could choose Cancel to exit the document picker and get back to the currently-open document without choosing a new one. While the new UIDocumentViewController behavior looks nice for apps like Swift Playgrounds, it is problematic for apps that want to take advantage of the UIDocument infrastructure without forcing the user to deal with a more complicated browser-centric app UI. I would expect there to be some way to maintain the previous behavior as it existed on iOS 17, but I don't see any way to do this. Suggestions welcome. Thanks!
7
0
319
Jun ’24
Correct Collection View "stretchy header" implementation?
Hello, I have the following subclass of UICompositionalCollectionViewLayout to get the stretchy header effect as shown below. It works quite well, but I don't really have an experience with creating custom layouts so I thought I'd ask if maybe my implementation doesn't have some important flaws. I once ran into persistent layout loop crash with this and I am not sure what exactly I changed but it stopped happening. However since I am using this layout on important screen, I would like to make sure there isn't obvious potential for the layout loop crash happening in App Store version. I am particularly unsure about the shouldInvalidateLayout implementation. Originally I was returning true all the time, but decided to change it and only force invalidation for negative content offset which is when my header is supposed to stretch. Here is the full code: final class StretchyCompositionalLayout: UICollectionViewCompositionalLayout { override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { var attrs = super.layoutAttributesForElements(in: rect) ?? [] guard let collectionView = collectionView else { return attrs } let contentOffset = collectionView.contentOffset.y guard contentOffset < 0 else { return attrs } var newAttributes: UICollectionViewLayoutAttributes? attrs.forEach({ attribute in if attribute.indexPath.section == 0 && attribute.indexPath.item == 0 { let startFrame = attribute.frame newAttributes = attribute.copy() as? UICollectionViewLayoutAttributes let newFrame: CGRect = .init(x: 0, y: contentOffset, width: startFrame.width, height: startFrame.height - contentOffset) newAttributes?.frame = newFrame } }) if let new = newAttributes { attrs.removeAll { attr in return attr.indexPath.section == 0 && attr.indexPath.item == 0 } attrs.insert(new, at: 0) } return attrs } override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { guard let attributes = super.layoutAttributesForItem(at: indexPath) else { return nil } let contentOffset = collectionView?.contentOffset.y ?? 1 guard contentOffset < 0 else { return attributes } if indexPath.section == 0 && indexPath.item == 0 { let attributes = attributes.copy() as? UICollectionViewLayoutAttributes ?? attributes let startFrame = attributes.frame let newFrame: CGRect = .init(x: 0, y: contentOffset, width: startFrame.width, height: startFrame.height - contentOffset) attributes.frame = newFrame return attributes } else { return super.layoutAttributesForItem(at: indexPath) } } override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { let contentOffset = collectionView?.contentOffset.y ?? 1 // There is visual glitch when 0 is used in this condition if contentOffset < 1 { return true } else { return super.shouldInvalidateLayout(forBoundsChange: newBounds) } } } Any feedback welcome!
0
0
153
2w
How to implement UITextItem in custom text view with UITextInput and TextKit2
Hi Apple, I'm implementing a custom text view by conforming to UITextInput and backing it with TextKit2. However, I like the UITextItem feature of the default UITextView. Can I get some guidance on how to reimplement it? Are we looking at overlaying UIMenu buttons? Or some API where I can display a UIMenu at a rect I specify? Hopefully, it is not some kind of private API? Thanks for the help in advance.
1
0
120
2w
Should iPadOS 18's UITabBarController work with more than 7 tabs?
Is it expected that UITabBarController in iPadOS 18 beta 2 should be working with more than 7 tabs yet, or is this still a work-in-progress on Apple's end? Currently, if I create a UITabBarController and configure it with more than 7 root tabs (i.e. enough to trigger the "more" tab in previous iPadOS versions) using the new UITab API, any tab after the seventh one is effectively not selectable: If the view is at a horizontally regular width: When you select via the new floating tab bar or the sidebar, the tab / sidebar item itself does become selected, but the actually displayed view controller remains unchanged. If you switch the window to a horizontally compact width, it switches to the old-style of tab bar, and the "More" tab with its moreNavigationController functionality becomes visible, and from there you select and actually present one of the 'excess' tabs. (Note: there appear to be some push/pop animation glitches when transitioning between the moreNavigationController and the tab's view controller) Then if you're in one of those 'more' tabs and then switch the window back to horizontally regular width: The currently displayed view controller (e.g. "view controller 9") is still shown, and the "More" back button along with it The new tab bar controls will act like some other tab is selected: specifically, whichever tab was selected when the window was last in the horizontally regular width mode If you tap on the "More" back button, you get the moreNavigationController and from that you can select any of the other overflow tabs (all the while with the old old tab showing as selected in the tab bar) If the moreNavigationController's tab list is visible, and you select one of the overflow tabs from the new tab bar or side bar, the correct view controller will be pushed onto the moreNavigationController's stack and show as selected in the new tab bar / side bar. (Hooray!) But this only appears to work specifically when the moreNavigationController's tab list is visible and there's nothing else on that navigation stack. Fundamentally, it feels like the work to sync the new tab management state with the moreNavigationController state isn't finished yet? But I've looked at the beta release notes and not seen any mention of these limitations. My questions, before I file any feedbacks: Are these known issues that are still being worked on? Is it Apple's intent that >7 root tabs should work by the time of iPadOS 18's release?
1
0
208
2w
Displaying HDR image, isn't showing dynamic range
I'm playing around with HDR images in iOS. I'm able to load an HDR image, but it isn't displaying with the expected "pop" I see of the same image in the Photos app. I exported the photo from Photos (on the Mac) using Export Unmodified. I reimported to confirm Photos shows the "pop." I'm trying both UIImage and CIImage, with the same results. The below is tested on my iPhone 14 Pro (not Simulator). The Storyboard for the code below has three UIImageViews (top, middle, and bottom). let fileURL = Bundle.main.url(forResource: "IMG_6972", withExtension:"HEIC")! var config = UIImageReader.Configuration() config.prefersHighDynamicRange = true let imageReader = UIImageReader(configuration: config) let topImage = imageReader.image(contentsOf: fileURL)! topImageView.preferredImageDynamicRange = .high topImageView.image = topImage // The image appears, looks SDR print("topImage.isHighDynamicRange: \(topImage.isHighDynamicRange)") // true let ciimage = CIImage(contentsOf: fileURL)! bottomImageView.image = UIImage(ciImage: ciimage) // The image appears, looks SDR - identical to topImage print("color space: \(ciimage.colorSpace!)") // (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; Display P3) let gainMap = CIImage(contentsOf: fileURL, options: [.auxiliaryHDRGainMap: true])! middleImageView.image = UIImage(ciImage: gainMap) // The gain map image appears as expected Additionally, for comparison, I tried: let sdrImage = UIImage(named: "IMG_6972.HEIC")! // UIImage.named doesn't support HDR print("sdrImage.isHighDynamicRange: \(sdrImage.isHighDynamicRange)")``` // false, as expected bottomImageView.image = sdrImage and the image matches the other two, further confirming the HDR version of the image isn't displaying in either UIImageReader or CIImage versions above. I also track the UIScreen's use of EDR with: print("currentEDR: \(UIScreen.main.currentEDRHeadroom)") print("maxEDR: \(UIScreen.main.potentialEDRHeadroom)") maxEDR is 8.0. currentEDR is 1.0 at launch, 1.3 after a 1.0 second delay. Which makes me think it might be showing a little HDR, but not enough to be noticeable. Is there something special I need to do to set the UIViewController, UIScreen, or UIApplication (etc) to be an an "HDR Mode" or similar?
1
0
170
2w
Share submenu in Mac Catalyst and UICommandTagShare
With Mac Catalyst, in Big Sur and Monterey, you could use UICommandTagShare as the property list for a UICommand in combination with activityItemsConfiguration and itemProvidersForActivityItemsConfiguration to allow a "Share" submenu to appear in a menu in your app (for instance, under the File menu like many other apps). Starting in Ventura, this submenu no longer appears with that same code, and instead the UICommandTagShare command in the menu now just displays "Share" with no submenu, which triggers a UIActivityViewController to appear in the main window. Is there any way to still allow a Share submenu to work in Ventura and beyond with Mac Catalyst? Thanks so much for any help!
1
1
389
Dec ’23
UI Tab Bar
Anyone else get these warnings when using UI Tab Bar in visionOS? Are these detrimental to pushing my visionOS app to the App Review Team? import SwiftUI import UIKit struct HomeScreenWrapper: UIViewControllerRepresentable { func makeUIViewController(context: Context) -> UITabBarController { let tabBarController = UITabBarController() // Home View Controller let homeVC = UIHostingController(rootView: HomeScreen()) homeVC.tabBarItem = UITabBarItem(title: "Home", image: UIImage(systemName: "house"), tag: 0) // Brands View Controller let brandsVC = UIHostingController(rootView: BrandSelection()) brandsVC.tabBarItem = UITabBarItem(title: "Brands", image: UIImage(systemName: "bag"), tag: 1) tabBarController.viewControllers = [homeVC, brandsVC] return tabBarController } func updateUIViewController(_ uiViewController: UITabBarController, context: Context) { // Update the UI if needed } } struct HomeScreenWrapper_Previews: PreviewProvider { static var previews: some View { HomeScreenWrapper() } }
1
0
198
2w
Crash when presenting UIPrintInteractionController on iOS 16
Starting iOS 16 seeing some crashes related to pdf printing in the crash reporter. It looks like the issue is not so frequent. Also, I'm unable to reproduce the crash. Looks like the app crashes when the print preview dialog is opening. According to crash reports, there are some crashes on different iOS 16 versions: 16.0.0, 16.0.2, and 16.0.3. Printing code: let printInfo = UIPrintInfo.printInfo() printInfo.jobName = "Printing Job Name" self.printViewController = UIPrintInteractionController.shared self.printViewController?.printInfo = printInfo self.printViewController?.printingItem = pdfURL self.printViewController?.present(from: barButtonItem, animated: true) { (controller, completed, error) in self.printViewController = nil } Stack trace: compare_key + 4 (CGPDFObject.c:134) bsearch + 68 (bsearch.c:70) CGPDFDictionaryGetUnresolvedObject + 68 (CGPDFDictionary.c:153) CGPDFDictionaryGetObject + 44 (CGPDFDictionary.c:172) CGPDFDictionaryGetDictionary + 44 (CGPDFDictionary.c:284) get_pages_dictionary + 68 (pdf-reader.c:410) pdf_reader_get_number_of_pages + 76 (pdf-reader.c:557) -[UIPrintPreviewPageFetcher fetchNumberOfItems] + 76 (UIPrintPreviewPageFetcher.m:115) -[UIPrintPreviewViewController collectionView:numberOfItemsInSection:] + 32 (UIPrintPreviewViewController.m:482) -[UICollectionViewData _updateItemCounts] + 220 (UICollectionViewData.mm:335) -[UICollectionViewData isIndexPathValid:validateItemCounts:] + 52 (UICollectionViewData.mm:348) -[UICollectionViewData validatedGlobalIndexForItemAtIndexPath:] + 36 (UICollectionViewData.mm:778) -[UICollectionView _cellForItemAtIndexPath:] + 108 (UICollectionView.m:7112) -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:collectionViewAnimator:] + 1384 (UICollectionView.m:9357) -[UICollectionView _updateRowsAtIndexPaths:updateAction:updates:] + 396 (UICollectionView.m:9104) -[UICollectionView reloadItemsAtIndexPaths:] + 52 (UICollectionView.m:9124) -[UIPrintPreviewViewController reloadVisibleItems:] + 256 (UIPrintPreviewViewController.m:568) __63-[UIPrintPreviewViewController updatePdfURL:options:completed:]_block_invoke_2 + 44 (UIPrintPreviewViewController.m:305) __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 24 (NSOperation.m:1545) -[NSBlockOperation main] + 104 (NSOperation.m:1564) __NSOPERATION_IS_INVOKING_MAIN__ + 16 (NSOperation.m:2189) -[NSOperation start] + 708 (NSOperation.m:2206) There is full stack trace I got from the Organizer Thanks!
13
5
3.6k
Oct ’22
The HEIC images in the Assets folder are displaying abnormally
I placed a PNG format image in the Assets folder and also added a HEIC format image that was converted from PNG. When the slicing is set to None, both images appear the same in the UIImageView. However, when I select "Horizontal and Vertical" for the Slices of both images, they no longer appear consistent, and the HEIC image displays abnormally. @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self addImageViews]; } - (void)addImageViews { UIImageView *heicImageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, [self imageViewSize].width,[self imageViewSize].height)]; UIImageView *pngImageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 300, [self imageViewSize].width,[self imageViewSize].height)]; heicImageView.image = [UIImage imageNamed:@"heic"]; pngImageView.image = [UIImage imageNamed:@"png"]; [self.view addSubview:heicImageView]; [self.view addSubview:pngImageView]; } - (CGSize)imageViewSize { return CGSizeMake(146, 44); } @end
1
0
121
2w