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

UIKit Documentation

Post

Replies

Boosts

Views

Activity

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.
7
1
664
Jun ’24
RoomPlan: textures for walls and floors.
After scanning the room I use the .export method passing a ModelProvider. Then I import the USDZ into a SCNView and continue processing the scene: I would like to apply a texture to the walls and floor, but I can't do it for the walls and floor because they don't contain the TextureCoordinates. Creating them from the USDZ file is not easy. I tried to combine the CapturedRoom data for the walls and floor only, adding the TextureCoordinates. I'm managing, but I'm struggling a lot. Isn't there an easier way to do it? Is there a ModelProvider planned for surfaces in the future? If so, where can I access the RoomPlan beta documentation?
1
1
390
Sep ’24
How do I enable UILargeContentViewerInteraction on UITabBar outside of UITabBarController?
UILargeContentViewerInteraction, added in iOS 13, works out of the box on the tab bar in a UITabBarController, and it's easy to set up on a custom view using the UILargeContentViewerItem properties on UIView. But how do I set it up on a UITabBar that's not connected to a UITabBarController? There don't appear to be any relevant properties on UITabBarItem. To try this, I made a sample app, added a tab bar, set up some items, set their largeContentSizeImage properties for good measure, ran the app, set text size to a large accessibility value, and long-pressed on the items, and I get no large content viewer. I also tried adding a UILargeContentViewerInteraction to the tab bar, and implemented the viewControllerForInteraction method in the delegate.
3
1
1k
Dec ’22
UITextView scrolling indicator cut off at top
Sample app A collection view controller with list layout, 1 section and 1 row. The cell's content view contains a text view. class ViewController: UICollectionViewController { var snapshot: NSDiffableDataSourceSnapshot<Section, String> { var snapshot = NSDiffableDataSourceSnapshot<Section, String>() snapshot.appendSections([.main]) snapshot.appendItems(["one", "two"], toSection: .main) return snapshot } var dataSource: UICollectionViewDiffableDataSource<Section, String>? enum Section { case main } init() { super.init(collectionViewLayout: .init()) collectionView.collectionViewLayout = createLayout() configureDataSource() // more likely and automatically avoid unpleasant animations on iOS 15 by configuring the data source in the init rather than in view did load } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } func configureDataSource() { let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, String> { cell, indexPath, itemIdentifier in let textView = UITextView() textView.font = .systemFont(ofSize: UIFont.labelFontSize) cell.contentView.addSubview(textView) textView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ textView.topAnchor.constraint(equalTo: cell.contentView.topAnchor, constant: 8), textView.bottomAnchor.constraint(equalTo: cell.contentView.bottomAnchor, constant: -8), textView.leadingAnchor.constraint(equalTo: cell.contentView.leadingAnchor, constant: cell.directionalLayoutMargins.leading), textView.trailingAnchor.constraint(equalTo: cell.contentView.trailingAnchor, constant: -cell.directionalLayoutMargins.trailing) ]) } dataSource = .init(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier) } dataSource?.apply(self.snapshot, animatingDifferences: false) } func createLayout() -> UICollectionViewLayout { return UICollectionViewCompositionalLayout { section, layoutEnvironment in let config = UICollectionLayoutListConfiguration(appearance: .insetGrouped) return NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment) } } } Question 1 Can anybody edit the provided sample code so that the text view's vertical indicator inset is not cut off at the top? Question 2 It seems to me that Apple has successfully implemented text views inside table view cells: can anybody provide Apple documentation as per how to do so? What I've tried and didn't work textView.verticalScrollIndicatorInsets.top = 30 // does nothing Adding the text view to a custom view and the view to the cell's content view textView.contentInset = .zero textView.scrollIndicatorInsets = .zero textView.textContainerInset = .zero textView.textContainer.lineFragmentPadding = 0 Centering the text view vertically and constraining its height to that of the content view with an 8 points constant to leave some padding Constraining the top and bottom anchors of the text view to the cell's layout margins guide's top and bottom anchors Constraint I need the text view to have some padding from the top and bottom of the cell for aesthetic reasons.
3
0
322
Aug ’24
The application crashes when an image of a certain PDF (50 MB, 1 page) is drawn on the context page in background.
Hi Team, I am using CGPDFPage and CGContext to convert the PDF to an image. It is working fine in all circumstances but fails in one circumstance where the size of the PDF is above 50 MB and when the application is made to be on background and again opened. It is also occurring only on physical devices; emulators are working fine. We are using the following code for this conversation: fileStream.CopyTo(memoryStream); CGDataProvider provider = new CGDataProvider(memoryStream.ToArray()); CGPDFDocument cGPDFDocument = null; image = null; cGPDFDocument = new CGPDFDocument(provider); using(CGPDFPage pdfPage = cGPDFDocument?.GetPage(1)) { if (pdfPage != null) { CGRect rect = pdfPage.GetBoxRect(CGPDFBox.Media); if (pdfPage.RotationAngle == 90 || pdfPage.RotationAngle == 270) { rect = new CGRect(rect.X, rect.Y, rect.Height, rect.Width); } nfloat factor = (nfloat)0.5; CGRect bounds = new CGRect(rect.X * factor, rect.Y * factor, rect.Width * factor, rect.Height * factor); UIGraphics.BeginImageContext(bounds.Size); CGContext context = UIGraphics.GetCurrentContext(); context.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f); context.FillRect(bounds); context.TranslateCTM(0, bounds.Height); context.ScaleCTM(factor, -factor); context.ConcatCTM(pdfPage.GetDrawingTransform(CGPDFBox.Crop, rect, 0, true)); context.SetRenderingIntent(CGColorRenderingIntent.Default); context.InterpolationQuality = CGInterpolationQuality.Default; context.DrawPDFPage(pdfPage); image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); imageView.Image = image; parentView.AddSubview(imageView); } } We have added a simple application created on Xamarin.iOS platform that replicates this issue in Assets we have added the PDF with this issue https://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfToImageSample-556012354 We have recorded this for the reference, https://www.syncfusion.com/downloads/support/directtrac/general/ze/CrashBGImgRec-1376481150 This issue is constantly occurring on the "context.DrawPDFPage(pdfPage);" line in my application. On the provided sample, this issue is occurring consistently when the break point is placed on the "context.DrawPDFPage(pdfPage);" line. It also occurs randomly without placing the breakpoint. We are invoking this function on DidEnterBackground override method of AppDelegate Do we need to set any to properly retrieve the image from CGPDFPage and add them into context?
1
0
462
Jun ’24
iPadOS in iOS18 with new UITabBarController ... UIBarButtonItems disappear
I have an iPad app using the new UITabBarController on iPadOS18, which is suffering from a new issue from the new layout. Within my tabs, I have a UISplitViewController, with a 2 column layout. If I load the app, it works ok, but if I put the app in the background, and then bring it to foreground, the navigation bar buttons and title just disappear from the splitView controller’s primary view controller. Before going to background: After coming back from background: I also get the following layout issues posted in the debugger consoler: Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "<NSLayoutConstraint:0x600002106ee0 UILayoutGuide:0x600003b088c0'TitleView(layout=0x103d18d40)'.trailing <= UILayoutGuide:0x600003b08c40'UIViewLayoutMarginsGuide'.trailing (active)>", "<NSLayoutConstraint:0x600002137520 H:|-(590)-[UILayoutGuide:0x600003b00a80'TabBarGuide(0x103d18810)'](LTR) (active, names: '|':_UINavigationBarContentView:0x103d18810 )>", "<NSLayoutConstraint:0x600002137610 UILayoutGuide:0x600003b00a80'TabBarGuide(0x103d18810)'.width == 0 (active)>", "<NSLayoutConstraint:0x6000021414a0 UILayoutGuide:0x600003b088c0'TitleView(layout=0x103d18d40)'.trailing >= UILayoutGuide:0x600003b00a80'TabBarGuide(0x103d18810)'.trailing (active)>", "<NSLayoutConstraint:0x600002148e10 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x103d18810.width == 585 (active)>", "<NSLayoutConstraint:0x600002107570 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x600003b08c40'UIViewLayoutMarginsGuide']-(20)-|(LTR) (active, names: '|':_UINavigationBarContentView:0x103d18810 )>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x600002106ee0 UILayoutGuide:0x600003b088c0'TitleView(layout=0x103d18d40)'.trailing <= UILayoutGuide:0x600003b08c40'UIViewLayoutMarginsGuide'.trailing (active)> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. I filed a bug report: FB14971801 Is there something I can do avoid this? It'll make my app pretty unusable if the bar button items just disappear every time the user puts the app in the background and then foregrounds the app.
1
0
643
Aug ’24
How can I use the F8 play/pause key to control media playback in Catalyst?
I have a Catalyst app that plays audio via AVQueuePlayer, and I'd like to use the system play/pause key (F8 on my MacBook Pro keyboard) to play and pause it. It doesn't seem to work automatically, and if I hook up a UIKeyCommand using UIKeyInputF8, it works with Fn-F8, not F8 on its own. It does seem to work in Overcast's Mac app, but I think that's an iPad app for Mac, not Catalyst, so it's probably going through whatever system pathway that the Lock Screen controls would be using on iOS. How do I make this work on Catalyst?
1
0
415
Aug ’24
MacOS Sequoia tab bar issues (a bug also happens in tvOS 18)
I found two tab bar issues: How do you programmatically hide/show the tab bar for iPadOS and Catalyst apps under macOS Sequoia? Also, is there a way to prevent the user from doing this via the menu? Programmatically changing the current tab view correctly changes the tab view but not the tab item highlighted in the tab bar in: Mac Catalyst apps under Sequoia iPad apps under Sequoia tvOS 18 apps Is there a workaround I can use until this bug is fixed?
2
0
607
Aug ’24
iOS 18 Navigation Title Bug
Hello. I'm encountering a strange behavior in iOS 18 and wanted to ask about it. When I run the following code on iOS 18, quotation marks appear in the navigation title. class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.title = " " self.view.backgroundColor = .systemBlue } } In versions prior to iOS 18, the title is displayed as intended, with nothing showing up. Could this be an intentional change in iOS 18, or is it a bug?
3
1
926
Aug ’24
Fold animation in UICollectionViewLayout
I want to achieve Fold animation when the user scrolls UICollectionView. I have UICollectionView with full-screen size cell and vertically scrolling with paging enabled. For that I've created sub-class of UICollectionViewFlowLayout which is as described below. class FoldingFlowLayout: UICollectionViewFlowLayout { private let logger = Logger(subsystem: bundleIdentifier, category: "FlowLayout") override func prepare() { super.prepare() scrollDirection = .vertical minimumLineSpacing = 0 minimumInteritemSpacing = 0 } override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { let attributes = super.layoutAttributesForElements(in: rect) attributes?.forEach { attribute in transformLayoutAttributes(attribute) } return attributes } override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { return true } private func transformLayoutAttributes(_ attributes: UICollectionViewLayoutAttributes) { guard let collectionView = collectionView else { return } let contentOffsetY = collectionView.contentOffset.y let cellOffsetY = attributes.frame.origin.y - contentOffsetY let cellHeight = attributes.frame.height var transform = CATransform3DIdentity transform.m34 = -1.0 / 500.0 // Apply perspective if cellOffsetY < cellHeight && cellOffsetY > -cellHeight { let angle = (cellOffsetY / cellHeight) * .pi / 2 transform = CATransform3DRotate(transform, angle, -1, 0, 0) attributes.transform3D = transform attributes.alpha = 1.0 - (abs(cellOffsetY) / cellHeight) } else { attributes.transform3D = CATransform3DIdentity attributes.alpha = 1.0 } } } But this is not working as I expected. I want to create replica of this kind of animation. What am I missing here?
1
0
435
Jul ’24
Edit menu on test selection has weird UI, specifically in my app
In our app, we noticed that edit menus (i.e. when long pressing in a text field) have weird spacing inside each element. Which, as a result, causes the entire menu content to be truncated. To be honest, I have no idea how this is being customized (to my understanding it shouldn't be?), but this is a relatively old and large app so something weird could possibly do it. I basically came here for guidance to see if anyone has thoughts on WHAT could possibly cause this customization / padding / resizing of each item, so I can fix it back to the system behavior. Our app: System: Thanks for your help :) Shai
1
0
240
Aug ’24
Reconfigure UICollectionView section
Problem When I reconfigure a collection view snapshot and apply it to my complex production collection view with list layout, the UI updates slowly, unless I don't animate the differences, even though I'm only reconfiguring the specific item identifiers of the cells that should be updated. I thought that maybe I could speed up the animations of the UI updates by applying the snapshot to a specific section (dataSource?.apply(sectionSnapshot, to: .main)) instead of to the whole collection view (dataSource?.apply(wholeSnapshot)). The problem is that I can't reconfigure the item identifiers of a single section snapshot to then apply the updated snapshot. Question Given the following sample app, can anybody edit reconfigureMainSection() so that, when invoked, the .main section cell registrations are called, consequently invoking print("Reconfiguring")? Sample app This collection view with list layout and diffable data source has 1 section and 2 rows. You can tap the right bar button item to call reconfigureMainSection(). class ViewController: UICollectionViewController { var snapshot: NSDiffableDataSourceSnapshot<Section, String> { var snapshot = NSDiffableDataSourceSnapshot<Section, String>() snapshot.appendSections([.main]) snapshot.appendItems(["one", "two"], toSection: .main) return snapshot } var dataSource: UICollectionViewDiffableDataSource<Section, String>? enum Section { case main } init() { super.init(collectionViewLayout: .init()) collectionView.collectionViewLayout = createLayout() configureDataSource() } override func viewDidLoad() { super.viewDidLoad() navigationItem.rightBarButtonItem = .init( title: "Reconfigure", style: .plain, target: self, action: #selector(reconfigureMainSection) ) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } func configureDataSource() { let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, String> { cell, indexPath, itemIdentifier in print("Reconfiguring") } dataSource = .init(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier) } dataSource?.apply(self.snapshot, animatingDifferences: false) } func createLayout() -> UICollectionViewLayout { return UICollectionViewCompositionalLayout { section, layoutEnvironment in let config = UICollectionLayoutListConfiguration(appearance: .plain) return NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment) } } @objc func reconfigureMainSection() { var sectionSnapshot = NSDiffableDataSourceSectionSnapshot<String>() sectionSnapshot.append(snapshot.itemIdentifiers(inSection: .main)) // reconfigure the section snapshot dataSource?.apply(sectionSnapshot, to: .main) } } Environment MacBook Air M1 8GB macOS Sonoma 14.5 Xcode 15.4 iPhone 15 Pro simulator on iOS 17.5
3
0
300
Aug ’24
iPadOS18 - UISplitViewController Navigation Title and Bar Button Items issue with Elevated Tab Bar
Having below issues with Navigation bar in UISplitViewController Primary View Controller, Navigation title is not showing with new Elevated Tab bar. Navigation right bar button is not showing. Navigation bar height issue with Primary and Secondary View Working fine in iPad OS 17. SplitViewController preferred display mode is preferredDisplayMode = UISplitViewController.DisplayMode.oneBesideSecondary Tested with Xcode 16.1 Beta and Xcode 16.0 Beta 6 iPad OS 18.1 iPadOS 17.5
3
1
508
Aug ’24
iOS 18 Beta UIPrintInteractionController present issue
I have a UIViewController that presents a UIPrintInteractionController when a user selects the print button on the UI. The problem is starting in iOS 18 (currently using beta 7) when the print controller is presented the UIViewController's viewWillAppear() is being called. This did not happen in earlier iOS releases and is causing unwanted behavior in the app. Is this a bug or will this be the behavior going forward?
2
0
522
Aug ’24
Xcode16 openURL is invalid
Xcode version: Xcode16 beta6 iOS version:iOS18 beta7 The openURL method call to UIApplication is invalid Moreover, the project has a lot of logic dependent on the return value of this method, which is very troublesome to modify Look at the Apple documentation, and say that the problem is fixed, how should I deal with this situation
1
0
687
Aug ’24
Issues with persistent SwiftUI.AppSceneDelegate causing black screen on app launch
For a few reasons, we as a team decided to transition away from the SwiftUI.App launch cycle. We need more control and customisation, and managing the scenes directly ourselves was the best way forward. We're now trying to run the app entirely from our own App and Scene delegates, however we've run into a problem: When we update the app on a device from a version that uses SwiftUI.App to a version that uses App and Scene delegates, the first initial launch fails with a black screen. The reason for this is that FrontBoardServices attempts to use the existing UISceneSession after the update, with the SwiftUI.AppSceneDelegate class, instead of calling application(configurationForConnecting:options:). Since SwiftUI.AppSceneDelegate still exists in the scope, the internal property _configurationNeedsReevaluation on UISceneSession returns false and the app attempts to launch from SwiftUI.AppSceneDelegate. As far as I can tell, there doesn't seem to be a way to fix this that doesn't involve invoking the private method -[UISceneSession _updateConfiguration:] to force the configuration to use the correct Scene delegate. if let sceneSession = application.openSessions.first( where: { $0.configuration.delegateClass.map(NSStringFromClass) == "SwiftUI.AppSceneDelegate" } ) { let newConfig = UISceneConfiguration(name: nil, sessionRole: .windowApplication) newConfig.delegateClass = SceneDelegate.self sceneSession.perform(Selector(("_updateConfiguration:")), with: newConfig) } Could you maybe advise on a way forwards?
2
0
370
Aug ’24
Regression in UITabBarController on Catalyst when building under Xcode 16
I am running into an issue with UITabBarController in a Catalyst app when building under Xcode 16 and running on macOS 15. If a UITabBarController is used, the tabs are presented in an unwanted title/toolbar at the top of the window. If you have an app where your views run to the top of the window, this can obscure the content and controls that are near the top. I created a sample application that is attached to the Feedback record (FB14293963). When building under Xcode 15, this is what the app looks like: Under Xcode 16, it looks like this: Beyond this simple example, using UITabBarController in a presented view controller can result in the tabs not showing at all. Also, If you switch the view in the main window to something that isn't a UITabBarController, the tabs still remain at the top. This seems to stem from the tab bar/sidebar changes for iPadOS 18. While this approach can work for simpler apps, it may not work well at all for more complex apps and there really needs to be a way to opt out of this behavior so apps where it is not suited for can still take advantage of features in iPadOS/Catalyst 18. Has anyone discovered a workaround or way to disable the new tab bar behavior with having to write their own version of UITabBarController?
1
0
630
Jul ’24