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

UIKit Documentation

Posts under UIKit subtopic

Post

Replies

Boosts

Views

Activity

[iOS18] QLPreviewController - No more swipe to dismiss?
Have the requirements to support swipe to dismiss from a quick-look view controller changed in iOS18? I am noticing that my app no longer supports gestural dismissal in an iOS18 build. Not this is a QLPreviewController presented from a UIViewController presented in a SwiftUI view hierarchy as part of a ViewControllerRepresentable.
4
1
1.7k
Aug ’24
UIDeferredMenuElement on MacCatalyst: closure called only once on first menu display
Hi folks, I'm struggling with an issue on MacCatalyst. I'm using a dynamic menu that is supposed to show the current state of a setting (state = .on / .off). The UIDeferredMenuElement works great on iOS, the closure is called on each display of the (context) menu. On MacCatalyst however - where I use the menu as a submenu in the main menu - the closure is called only once on first menu display. The system seems to show a cached menu item even though I'm using UIDeferredMenuElement.uncached. Here's the relevant code: func getMenuElement() { let element = UIDeferredMenuElement.uncached { completion in let modeString = mode.myLocalizedDescription let trackingMode = <current setting> let mode = <menu item setting option> let state = trackingMode == mode ? .on : .off let action = UIAction(title: modeString, image: <image>, state: state) { _ in viewController.setUserTrackingMode(mode) } completion([action]) } return element } Any ideas how to trick the system into generating the dynamic menu item on each menu display?
1
0
456
Aug ’24
PullDown menu shows in reverse order when in landscape
I create a UIKit PullDown menu (in a positionMenu button), with the following code: func setupPullDownMenu() { let menu1 = UIAction(title: "Menu1") { [self] _ in // some code } let menu2 = UIAction(title: "Menu2") { [self] _ in // some code } let menu3 = UIAction(title: "Menu3") { [self] _ in // some code } let menu = UIMenu(title: "Positions", children: [menu1, menu2, menu3]) positionMenu.menu = menu positionMenu.showsMenuAsPrimaryAction = true }   In Portrait, options are listed as Menu1, Menu2, Menu3 But in Landscape it is the reverse: Menu3, Menu2, Menu1 I use Xcode 16.1ß and iOS 17.0 simulator Is it the expected behaviour ?
1
0
831
Aug ’24
UITableView: Adjust destination index path when dragging and dropping from another view
When reordering items within a table view, I can use tableView:targetIndexPathForMoveFromRowAtIndexPath: to adjust the destination index path. Is there a way to adjust the destination index path when dropping onto a table view if the drag was initiated in a different view? For example, if I'm dropping an object into a table view where the rows are sorted alphabetically, I want the gap to appear in the location where the item is going to end up, regardless of which row the dragged item is being dragged / dropped at.
Topic: UI Frameworks SubTopic: UIKit
1
0
365
Aug ’24
UlTextView erroneously overrides string attributes when applying spellchecker annotation attributes (regression)
UITextView erroneously overrides string attributes when applying spellchecker annotation attributes. It doesn't need any particular setting. Default UITextView instance with attributed text let textView = UITextView(usingTextLayoutManager: true) textView.spellCheckingType = .yes Once spellcheck attributes get applied, other attributes like foreground color get applied to the misspelled words. This behavior happens only on Mac Catalyst, and started to appear on macOS 14 or newer. Please check the Xcode project that demonstrates the issue https://github.com/user-attachments/files/16689336/TextEditor-FB14165227.zip Open TextEditor project Select "My Mac (Mac Catalyst)" build destination Run the project. A window with a text area should appear Select the whole text (either using mouse or keyboard command+a) Observe how foregroundColor changes to text (this is the issue) That eventually led to crash 💥 This bug is reported to Apple FB14165227
1
0
811
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
589
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
1.8k
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
921
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
1.7k
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
Topic: UI Frameworks SubTopic: UIKit
3
0
452
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
969
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
851
Aug ’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
394
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
639
Aug ’24
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.
Topic: UI Frameworks SubTopic: UIKit Tags:
3
0
527
Aug ’24