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

UIKit Documentation

Posts under UIKit tag

719 Posts
Sort by:
Post not yet marked as solved
0 Replies
12 Views
I have a custom rotor that changes the skim speed of the skim forward/backward feature of my audio player. The rotor works, but it's always playing an end-of-list sound. Here is the code: // Member variables private let accessibilitySeekSpeeds: [Double] = [10, 30, 60, 180] // seconds private var accessibilitySeekSpeedIndex: Int = 0 func seekSpeedRotor() -> UIAccessibilityCustomRotor { UIAccessibilityCustomRotor(name: "seek speed") { [weak self] predicate in guard let self = self else { return nil } let speeds = accessibilitySeekSpeeds switch predicate.searchDirection { case .previous: accessibilitySeekSpeedIndex = (accessibilitySeekSpeedIndex - 1 + speeds.count) % speeds.count case .next: accessibilitySeekSpeedIndex = (accessibilitySeekSpeedIndex + 1) % speeds.count @unknown default: break } // Return the currently selected speed as an accessibility element let accessibilityElement = UIAccessibilityElement(accessibilityContainer: self) let currentSpeed = localizedDuration(seconds: speeds[accessibilitySeekSpeedIndex]) accessibilityElement.accessibilityLabel = currentSpeed + " seek speed" UIAccessibility.post(notification: .announcement, argument: currentSpeed + " seek speed") return UIAccessibilityCustomRotorItemResult(targetElement: accessibilityElement, targetRange: nil) } } The returned accessibility element isn't read out, and instead an end-of-list sound is played. I can announce the change manually using UIAccessibility.post, but it still plays the end-of-list sound. How can I prevent the rotor from playing the end-of-list sound?
Posted
by
Post not yet marked as solved
0 Replies
42 Views
I am getting this error, only in iOS 17 (all version) on old code that had been working since iOS 15. The error occurs whenever the collectionView need to increase it's height beyond its initial height. The collectionView is inside a tableView. All autolayout constraints are set and everything use to work fine in previous version of iOS. *** Assertion failure in -[MYAPP.MYCollectionView _updateLayoutAttributesForExistingVisibleViewsFadingForBoundsChange:], UICollectionView.m:6218
Posted
by
Post not yet marked as solved
0 Replies
59 Views
■Confirmation (2 points) ① Question about setting Constraints for UIScrollView. Is it correct to align the display position of the top edge of ContentsView, which contains the actual displayed content, with "ContentLayoutGuide" instead of "FrameLayoutGuide"? ② Is there a difference in screen display control between Xcode 14.1 and earlier and Xcode 15.0 when multiple Constraints are set for the same screen component? ■Background of the question On the screen that implements UIScrollView, the following two constraints regarding the display position of the top edge of ContentsView were set. Match the top of "FrameLayoutGuide". Match the top of "ContentLayoutGuide". Also, the priorities of the above two Constraints were the same. In Xcode 14.1, I was able to scroll the screen without any problems. When I upgraded to Xcode 15.0, the following error message appeared and I was unable to scroll. Unable to simultaneously satisfy constraints.
Posted
by
Post marked as solved
1 Replies
71 Views
Please run the following UIKit app. It uses a collection view with compositional layout (list layout) and a diffable data source. The collection view has one section with one row. The cell contains a text field that is pinned to its contentView. import UIKit class ViewController: UIViewController { var collectionView: UICollectionView! var dataSource: UICollectionViewDiffableDataSource<String, String>! override func viewDidLoad() { super.viewDidLoad() configureHierarchy() configureDataSource() } func configureHierarchy() { collectionView = .init(frame: .zero, collectionViewLayout: createLayout()) view.addSubview(collectionView) collectionView.frame = view.bounds } func createLayout() -> UICollectionViewLayout { UICollectionViewCompositionalLayout { section, layoutEnvironment in let config = UICollectionLayoutListConfiguration(appearance: .insetGrouped) return NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment) } } func configureDataSource() { let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, String> { cell, indexPath, itemIdentifier in let textField = UITextField() textField.placeholder = "Placeholder" textField.font = .systemFont(ofSize: 100) cell.contentView.addSubview(textField) textField.pinToSuperview() } dataSource = .init(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier) } var snapshot = NSDiffableDataSourceSnapshot<String, String>() snapshot.appendSections(["main"]) snapshot.appendItems(["demo"]) dataSource.apply(snapshot, animatingDifferences: false) } } extension UIView { func pin( to object: CanBePinnedTo, top: CGFloat = 0, bottom: CGFloat = 0, leading: CGFloat = 0, trailing: CGFloat = 0 ) { self.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ self.topAnchor.constraint(equalTo: object.topAnchor, constant: top), self.bottomAnchor.constraint(equalTo: object.bottomAnchor, constant: bottom), self.leadingAnchor.constraint(equalTo: object.leadingAnchor, constant: leading), self.trailingAnchor.constraint(equalTo: object.trailingAnchor, constant: trailing), ]) } func pinToSuperview( top: CGFloat = 0, bottom: CGFloat = 0, leading: CGFloat = 0, trailing: CGFloat = 0, file: StaticString = #file, line: UInt = #line ) { guard let superview = self.superview else { print(">> \(#function) failed in file: \(String.localFilePath(from: file)), at line: \(line): could not find \(Self.self).superView.") return } self.pin(to: superview, top: top, bottom: bottom, leading: leading, trailing: trailing) } func pinToSuperview(constant c: CGFloat = 0, file: StaticString = #file, line: UInt = #line) { self.pinToSuperview(top: c, bottom: -c, leading: c, trailing: -c, file: file, line: line) } } @MainActor protocol CanBePinnedTo { var topAnchor: NSLayoutYAxisAnchor { get } var bottomAnchor: NSLayoutYAxisAnchor { get } var leadingAnchor: NSLayoutXAxisAnchor { get } var trailingAnchor: NSLayoutXAxisAnchor { get } } extension UIView: CanBePinnedTo { } extension UILayoutGuide: CanBePinnedTo { } extension String { static func localFilePath(from fullFilePath: StaticString = #file) -> Self { URL(fileURLWithPath: "\(fullFilePath)").lastPathComponent } } Unfortunately, as soon as I insert a leading view in the cell: let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, String> { cell, indexPath, itemIdentifier in let contentView = cell.contentView let leadingView = UIView() leadingView.backgroundColor = .systemRed let textField = UITextField() textField.placeholder = "Placeholder" textField.font = .systemFont(ofSize: 100) contentView.addSubview(leadingView) contentView.addSubview(textField) leadingView.translatesAutoresizingMaskIntoConstraints = false textField.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ leadingView.centerYAnchor.constraint(equalTo: contentView.layoutMarginsGuide.centerYAnchor), leadingView.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor), leadingView.widthAnchor.constraint(equalTo: contentView.layoutMarginsGuide.heightAnchor), leadingView.heightAnchor.constraint(equalTo: contentView.layoutMarginsGuide.heightAnchor), textField.topAnchor.constraint(equalTo: contentView.topAnchor), textField.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), textField.leadingAnchor.constraint(equalTo: leadingView.trailingAnchor, constant: 16), textField.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor), textField.heightAnchor.constraint(greaterThanOrEqualToConstant: 44) ]) } the cell does not self-size, and in particular it does not accomodate the text field: What would be the best way to make the cell resize automatically?
Posted
by
Post not yet marked as solved
0 Replies
82 Views
Please run the following UIKit app. It uses a collection view with compositional layout (list layout) and a diffable data source. It has one section with one row. The cell has an image view as a leading accessory. Unfortunately, as soon as I set an image for the image view, the accessory is no longer centered: import UIKit class ViewController: UIViewController { var collectionView: UICollectionView! var dataSource: UICollectionViewDiffableDataSource<String, String>! override func viewDidLoad() { super.viewDidLoad() configureHierarchy() configureDataSource() } func configureHierarchy() { collectionView = .init(frame: .zero, collectionViewLayout: createLayout()) view.addSubview(collectionView) collectionView.frame = view.bounds } func createLayout() -> UICollectionViewLayout { UICollectionViewCompositionalLayout { section, layoutEnvironment in let config = UICollectionLayoutListConfiguration(appearance: .insetGrouped) return NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment) } } func configureDataSource() { let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, String> { cell, indexPath, itemIdentifier in let iv = UIImageView() iv.backgroundColor = .systemRed // iv.image = .init(systemName: "camera") iv.contentMode = .scaleAspectFit iv.frame.size = .init( width: 40, height: 40 ) cell.accessories = [.customView(configuration: .init( customView: iv, placement: .leading(), reservedLayoutWidth: .actual, maintainsFixedSize: true ))] } dataSource = .init(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier) } var snapshot = NSDiffableDataSourceSnapshot<String, String>() snapshot.appendSections(["main"]) snapshot.appendItems(["demo"]) dataSource.apply(snapshot, animatingDifferences: false) } } This seems like a bug but then if I set the image view's size to 100x100, even without giving it an image, the cell doesn't resize, which makes me think I'm making a mistake.
Posted
by
Post not yet marked as solved
2 Replies
112 Views
I am puzzled by a deluge of warnings like "This code path does I/O on the main thread underneath that can lead to UI responsiveness issues. Consider ways to optimize this code path" on code that sems perfectly inocuous, like `class FileOrFolderCell: UICollectionViewCell { //... let emojiLabelInitialFontSize: CGFloat = 64. //<--- flagged as a potential hang pont (wha!!?) //... var isNew = false { //<--- potential hang point didSet { newBadge.isHidden = !isNew } } //.... }` Can anybody offer insights on how to address this? Thanks.
Posted
by
Post not yet marked as solved
1 Replies
112 Views
The following is a UIKit app with a collection view with one section, whose supplementary view sports a search bar. When you type, it often resigns first responder. import UIKit class ViewController: UIViewController { let words = ["foo", "bar"] var filteredWords = ["foo", "bar"] { didSet { dataSource.apply(self.snapshot) } } var collectionView: UICollectionView! var dataSource: UICollectionViewDiffableDataSource<String, String>! var snapshot: NSDiffableDataSourceSnapshot<String, String> { var snapshot = NSDiffableDataSourceSnapshot<String, String>() snapshot.appendSections(["main"]) snapshot.appendItems(filteredWords) return snapshot } override func viewDidLoad() { super.viewDidLoad() navigationItem.rightBarButtonItem = .init(title: "Apply", style: .plain, target: self, action: #selector(apply)) configureHierarchy() configureDataSource() } @objc func apply() { dataSource.apply(self.snapshot) } func configureHierarchy() { collectionView = .init(frame: .zero, collectionViewLayout: createLayout()) view.addSubview(collectionView) collectionView.frame = view.bounds collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight] } func createLayout() -> UICollectionViewLayout { UICollectionViewCompositionalLayout { section, layoutEnvironment in var config = UICollectionLayoutListConfiguration(appearance: .insetGrouped) config.headerMode = .supplementary return NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment) } } func configureDataSource() { let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, String> { _, _, _ in } dataSource = .init(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier) } let searchbarHeaderRegistration = UICollectionView.SupplementaryRegistration<SearchBarCell>(elementKind: UICollectionView.elementKindSectionHeader) { cell, elementKind, indexPath in cell.searchBar.delegate = self } dataSource.supplementaryViewProvider = { collectionView, kind, indexPath in collectionView.dequeueConfiguredReusableSupplementary(using: searchbarHeaderRegistration, for: indexPath) } dataSource.apply(self.snapshot, animatingDifferences: false) } } extension ViewController: UISearchBarDelegate { func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { DispatchQueue.main.async { [weak self] in guard let self else { return } filteredWords = words.filter { $0.hasPrefix(searchText) } } } func searchBarTextDidEndEditing(_ searchBar: UISearchBar) { DispatchQueue.main.async { [weak self] in guard let self else { return } filteredWords = words } } } class SearchBarCell: UICollectionViewListCell { let searchBar = UISearchBar() override init(frame: CGRect) { super.init(frame: frame) contentView.addSubview(searchBar) searchBar.pinToSuperview() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } extension UIView { func pin( to object: CanBePinnedTo, top: CGFloat = 0, bottom: CGFloat = 0, leading: CGFloat = 0, trailing: CGFloat = 0 ) { self.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ self.topAnchor.constraint(equalTo: object.topAnchor, constant: top), self.bottomAnchor.constraint(equalTo: object.bottomAnchor, constant: bottom), self.leadingAnchor.constraint(equalTo: object.leadingAnchor, constant: leading), self.trailingAnchor.constraint(equalTo: object.trailingAnchor, constant: trailing), ]) } func pinToSuperview( top: CGFloat = 0, bottom: CGFloat = 0, leading: CGFloat = 0, trailing: CGFloat = 0, file: StaticString = #file, line: UInt = #line ) { guard let superview = self.superview else { print(">> \(#function) failed in file: \(String.localFilePath(from: file)), at line: \(line): could not find \(Self.self).superView.") return } self.pin(to: superview, top: top, bottom: bottom, leading: leading, trailing: trailing) } func pinToSuperview(constant c: CGFloat = 0, file: StaticString = #file, line: UInt = #line) { self.pinToSuperview(top: c, bottom: -c, leading: c, trailing: -c, file: file, line: line) } } @MainActor protocol CanBePinnedTo { var topAnchor: NSLayoutYAxisAnchor { get } var bottomAnchor: NSLayoutYAxisAnchor { get } var leadingAnchor: NSLayoutXAxisAnchor { get } var trailingAnchor: NSLayoutXAxisAnchor { get } } extension UIView: CanBePinnedTo { } extension UILayoutGuide: CanBePinnedTo { } extension String { static func localFilePath(from fullFilePath: StaticString = #file) -> Self { URL(fileURLWithPath: "\(fullFilePath)").lastPathComponent } } By the way if you remove the dispatch blocks, the app simply crashes complaining that you're trying to apply datasource snapshots from both the main queue and other queues. Xcode 15.3 iOS 17.4 simulator, MacBook Air M1 8GB macOS Sonoma 14.4.1
Posted
by
Post not yet marked as solved
0 Replies
96 Views
On ios15, when you minimise app and then come back to it, labels in tabs become truncated. When you tap on them they return to normal state again, after that you can minimise again and everything will be ok This only happens for a specific font size, in my case it is system 12 bold/regular Start screen: After returning to the app: Is there something I can do about it?
Posted
by
Post not yet marked as solved
0 Replies
94 Views
We are developing an cross platform Enterprise grade application in MAUI. Net for our Organization and while displaying alerts using UIAlertController, alerts are displayed along with App Icon with not available symbol on top of it in MacOS. We are generating the iPadOS apps and generating M1 Mac packages using productbuild command and deploying them to mac books. Under Show Package content I can see the app file is having this image and by default it showing this icon. Is there any possibility to generate packages without this icon? In UIAlertController is there any possibility to hide the app icon as it coming by default without mentioning to display the icon I am looking for removing the not available symbol on top of our logo or is there any possibility to hide the app icon from UIAlertcontroller as I m not seeing any options to remove this. Thanks Ranga
Posted
by
Post not yet marked as solved
1 Replies
105 Views
The following is a UIKit app that uses a collection view with list layout and a diffable data source. It displays one section that has 10 empty cells and then final cell whose content view contains a text view, that is pinned to the content view's layout margins guide. The text view's scrolling is set to false, so that the line collectionView.selfSizingInvalidation = .enabledIncludingConstraints will succeed at making the text view's cell resize automatically and animatedly as the text changes. import UIKit class ViewController: UIViewController { var collectionView: UICollectionView! var dataSource: UICollectionViewDiffableDataSource<String, Int>! let textView: UITextView = { let tv = UITextView() tv.text = "Text" tv.isScrollEnabled = false return tv }() override func viewDidLoad() { super.viewDidLoad() configureHierarchy() configureDataSource() if #available(iOS 16.0, *) { collectionView.selfSizingInvalidation = .enabledIncludingConstraints } } func configureHierarchy() { collectionView = .init(frame: .zero, collectionViewLayout: createLayout()) view.addSubview(collectionView) collectionView.frame = view.bounds collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight] } func createLayout() -> UICollectionViewLayout { let configuration = UICollectionLayoutListConfiguration(appearance: .insetGrouped) return UICollectionViewCompositionalLayout.list(using: configuration) } func configureDataSource() { let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, Int> { _, _, _ in } let textViewCellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, Int> { [weak self] cell, _, _ in guard let self else { return } cell.contentView.addSubview(textView) textView.pin(to: cell.contentView.layoutMarginsGuide) } dataSource = .init(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in if indexPath.row == 10 { collectionView.dequeueConfiguredReusableCell(using: textViewCellRegistration, for: indexPath, item: itemIdentifier) } else { collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier) } } var snapshot = NSDiffableDataSourceSnapshot<String, Int>() snapshot.appendSections(["section"]) snapshot.appendItems(Array(0...10)) dataSource.apply(snapshot) } } extension UIView { func pin( to object: CanBePinnedTo, top: CGFloat = 0, bottom: CGFloat = 0, leading: CGFloat = 0, trailing: CGFloat = 0 ) { self.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ self.topAnchor.constraint(equalTo: object.topAnchor, constant: top), self.bottomAnchor.constraint(equalTo: object.bottomAnchor, constant: bottom), self.leadingAnchor.constraint(equalTo: object.leadingAnchor, constant: leading), self.trailingAnchor.constraint(equalTo: object.trailingAnchor, constant: trailing), ]) } } @MainActor protocol CanBePinnedTo { var topAnchor: NSLayoutYAxisAnchor { get } var bottomAnchor: NSLayoutYAxisAnchor { get } var leadingAnchor: NSLayoutXAxisAnchor { get } var trailingAnchor: NSLayoutXAxisAnchor { get } } extension UIView: CanBePinnedTo { } extension UILayoutGuide: CanBePinnedTo { } How do I make the UI move to accomodate the keyboard once you tap on the text view and also when the text view changes size, by activating the view.keyboardLayoutGuide.topAnchor constraint, as shown in the WWDC21 video "Your guide to keyboard layout"? My code does not resize the text view on iOS 15, only on iOS 16+, so clearly the solution may allow the UI to adjust to text view changes on iOS 16+ only. Recommended, modern, approach: Not recommended, old, approach: I've tried to say view.keyboardLayoutGuide.topAnchor.constraint(equalTo: textView.bottomAnchor).isActive = true in the text view cell registration, as well as view.keyboardLayoutGuide.topAnchor.constraint(equalTo: collectionView.bottomAnchor).isActive = true in viewDidLoad(), but both of these approaches fail (Xcode 15.3 iPhone 15 Pro simulator with iOS 17.4, physical iPhone SE on iOS 15.8).
Posted
by
Post marked as solved
1 Replies
104 Views
The following UIKit swift app uses a table view with 2 sections. The first section displays a custom cell with a text view, which was added to the cell’s contentView and anchored to the ladder’s layoutMarginsGuide’s top, bottom, leading and trailing anchors. The second section displays a custom cell that is like the former but with a text field instead of a text view. Both sections have titles defined in the tableView(_:cellForRowAt:) method. If you run the app, you will see that the text view’s text is not vertically aligned to it’s section’s title, whereas the text field’s is. How do I align the text view’s text as well? import UIKit class ViewController: UIViewController { let tableView = UITableView() override func viewDidLoad() { super.viewDidLoad() view.addSubview(tableView) tableView.frame = view.bounds tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight] tableView.dataSource = self tableView.register(TextViewCell.self, forCellReuseIdentifier: TextViewCell.identifier) tableView.register(TextFieldCell.self, forCellReuseIdentifier: TextFieldCell.identifier) } } extension ViewController: UITableViewDataSource { func numberOfSections(in tableView: UITableView) -> Int { 2 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 1 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.section == 0 { tableView.dequeueReusableCell(withIdentifier: TextViewCell.identifier, for: indexPath) } else { tableView.dequeueReusableCell(withIdentifier: TextFieldCell.identifier, for: indexPath) } } func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { "Title \(section)" } } extension UITableViewCell { static var identifier: String { "\(Self.self)" } } class TextViewCell: UITableViewCell { let textView: UITextView = { let tv = UITextView() tv.text = "Text view" tv.font = .preferredFont(forTextStyle: .title2) tv.backgroundColor = .systemRed tv.isScrollEnabled = false return tv }() override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) contentView.addSubview(textView) textView.pin(to: contentView.layoutMarginsGuide) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } class TextFieldCell: UITableViewCell { let textField: UITextField = { let tf = UITextField() tf.text = "Text field" tf.backgroundColor = .systemBlue return tf }() override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) contentView.addSubview(textField) textField.pin(to: contentView.layoutMarginsGuide) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } Here's how the pin(to:) function is defined in case you're wondering: import UIKit extension UIView { func pin( to object: CanBePinnedTo, top: CGFloat = 0, bottom: CGFloat = 0, leading: CGFloat = 0, trailing: CGFloat = 0 ) { self.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ self.topAnchor.constraint(equalTo: object.topAnchor, constant: top), self.bottomAnchor.constraint(equalTo: object.bottomAnchor, constant: bottom), self.leadingAnchor.constraint(equalTo: object.leadingAnchor, constant: leading), self.trailingAnchor.constraint(equalTo: object.trailingAnchor, constant: trailing), ]) } } @MainActor protocol CanBePinnedTo { var topAnchor: NSLayoutYAxisAnchor { get } var bottomAnchor: NSLayoutYAxisAnchor { get } var leadingAnchor: NSLayoutXAxisAnchor { get } var trailingAnchor: NSLayoutXAxisAnchor { get } } extension UIView: CanBePinnedTo { } extension UILayoutGuide: CanBePinnedTo { }
Posted
by
Post not yet marked as solved
0 Replies
118 Views
Hi everyone! Anyone else seeing crashes like this: Fatal Exception: NSInvalidArgumentException. -[_UISnapshotWindow actualSceneBounds]: unrecognized selector sent to instance I'm encountering a crash within 3-4 seconds of launching my iOS app specifically on devices running iOS 14. The crash log indicates an NSInvalidArgumentException with the following message: `Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x129754 __exceptionPreprocess 1 libobjc.A.dylib 0x287a8 objc_exception_throw 2 CoreFoundation 0x2cc3c -[NSOrderedSet initWithSet:copyItems:] 3 UIKitCore 0xc01ea0 -[UIResponder doesNotRecognizeSelector:] 4 CoreFoundation 0x12c2ac ___forwarding___ 5 CoreFoundation 0x12e5b0 _CF_forwarding_prep_0 6 UIKitCore 0xa918cc -[UIUndoGestureInteraction didMoveToView:] 7 UIKitCore 0x11099b4 _setInteractionView 8 UIKitCore 0x11098bc -[UIView(Dragging) addInteraction:] 9 UIKitCore 0xe9d678 -[UIEditingOverlayViewController _addInteractions] 10 UIKitCore 0x4a73e4 -[UIViewController _setViewAppearState:isAnimating:] 11 UIKitCore 0x4a7910 __52-[UIViewController _setViewAppearState:isAnimating:]_block_invoke 12 CoreFoundation 0xa75bc __NSARRAY_IS_CALLING_OUT_TO_A_BLOCK__ 13 CoreFoundation 0x2410 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] 14 UIKitCore 0x4a75ac -[UIViewController _setViewAppearState:isAnimating:] 15 UIKitCore 0x4a7dc0 -[UIViewController __viewDidAppear:] 16 UIKitCore 0x4a9964 __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke 17 UIKitCore 0x4a873c -[UIViewController _executeAfterAppearanceBlock] 18 UIKitCore 0xbda7c4 _runAfterCACommitDeferredBlocks 19 UIKitCore 0xbc903c _cleanUpAfterCAFlushAndRunDeferredBlocks 20 UIKitCore 0xbfcf10 _afterCACommitHandler 21 CoreFoundation 0xa25e0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ 22 CoreFoundation 0x9c704 __CFRunLoopDoObservers 23 CoreFoundation 0x9ccb0 __CFRunLoopRun 24 CoreFoundation 0x9c360 CFRunLoopRunSpecific 25 GraphicsServices 0x3734 GSEventRunModal 26 UIKitCore 0xbca584 -[UIApplication _run] 27 UIKitCore 0xbcfdf4 UIApplicationMain 28 JobLogic 0x1d9ac4 main + 14 (main.m:14) 29 libdyld.dylib 0x1cf8 start` Here's what I've observed: The crash consistently occurs within 3-4 seconds of app launch on iOS 14 devices. I'm seeking assistance with: Understanding the Cause: Any insights into potential causes of this crash, particularly related to _[_UISnapshotWindow actualSceneBounds] and its interaction with iOS 14, would be greatly appreciated. Replication Steps: If possible, guidance on how to reliably replicate the crash on a development device would be extremely helpful for debugging purposes. Solutions: Any suggestions or known workarounds to address this specific crash or similar issues in iOS 14 would be invaluable.
Posted
by
Post not yet marked as solved
0 Replies
75 Views
I tried to create the demo with the code import UIKit class ViewController: UIDocumentBrowserViewController, UIDocumentBrowserViewControllerDelegate { override func viewDidLoad() { super.viewDidLoad() self.browserUserInterfaceStyle = .dark let button = UIBarButtonItem(title: "First", style: .plain, target: nil, action: #selector(action(_:))) let button2 = UIBarButtonItem(title: "Second", style: .plain, target: nil, action: #selector(action(_:))) self.additionalLeadingNavigationBarButtonItems = [button, button2] } @objc func action(_ sender: UIBarButtonItem) { showAlert(with: sender) } func showAlert(with button: UIBarButtonItem) { let controller = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) let action = UIAlertAction(title: "Test", style: .default) controller.addAction(action) controller.addAction(action) let presentationPopover = controller.popoverPresentationController presentationPopover?.sourceItem = button present(controller, animated: true) } } But the action sheet is in the wrong position when the user taps the button bar. This issue only happens when the user switches between the share and recent options before tapping the bar button.
Posted
by
Post not yet marked as solved
0 Replies
257 Views
Though I cannot find any documentation, it seems that UIPasteboard cannot be used from a Quick Look Preview app extension. I have such an extension, which contains a view that supports copying text as follows: - (IBAction)copy:(nullable id)sender { UIPasteboard * pboard = UIPasteboard.generalPasteboard; pboard.string = _rep.text; } This is invoked from a context menu (edit menu) item. This works fine In the simulator, but on device the pasteboard remains empty and errors like the following are emitted: -[PBServerConnection pasteboardWithName:createIfNeeded:authenticationBlock:dataOwnerBlock:error:] failed with error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.pasteboard.pasted was invalidated: failed at lookup with error 159 - Sandbox restriction." UserInfo={NSDebugDescription=The connection to service named com.apple.pasteboard.pasted was invalidated: failed at lookup with error 159 - Sandbox restriction.} It's unclear to me why such functionality would be problematic and necessary to block. It would be nice if this were documented clearly, as I wasted a lot of time trying to figure out why this was not working. (And no, I have not filed a feedback report or TSI yet, as I'm presently very short on time, and I don't have a sample project prepared to demonstrate the issue.)
Posted
by
Post not yet marked as solved
4 Replies
362 Views
hi I have been using WKWebView embedded in a UIViewRepresentable for displaying inside a SwiftUI View hierarchy, but when I try the same code on 17,5 beta (simulator) the code fails. In fact, the code runs (no exceptions raised or anything) but the web view does not render. In the console logs I see: Warning: -[BETextInput attributedMarkedText] is unimplemented Error launching process, description 'The operation couldn’t be completed. (OSStatus error -10814.)', reason '' The code I am using to present the view is: struct MyWebView: UIViewRepresentable { let content: String func makeUIView(context: Context) -> WKWebView { // Javascript that disables pinch-to-zoom by inserting the HTML viewport meta tag into <head> let source: String = """ var meta = document.createElement('meta'); meta.name = 'viewport'; meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'; var style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = '*:focus{outline:none}body{margin:0;padding:0}'; var head = document.getElementsByTagName('head')[0]; head.appendChild(meta); head.appendChild(style); """ let script: WKUserScript = WKUserScript(source: source, injectionTime: .atDocumentEnd, forMainFrameOnly: true) let userContentController: WKUserContentController = WKUserContentController() let conf = WKWebViewConfiguration() conf.userContentController = userContentController userContentController.addUserScript(script) let webView = WKWebView(frame: CGRect.zero /*CGRect(x: 0, y: 0, width: 1000, height: 1000)*/, configuration: conf) webView.isOpaque = false webView.backgroundColor = UIColor.clear webView.scrollView.backgroundColor = UIColor.clear webView.scrollView.isScrollEnabled = false webView.scrollView.isMultipleTouchEnabled = false if #available(iOS 16.4, *) { webView.isInspectable = true } return webView } func updateUIView(_ webView: WKWebView, context: Context) { webView.loadHTMLString(content, baseURL: nil) } } This has been working for ages and ages (back to at least ios 15) - something changed. Maybe it is just a problem with the beta 17.5 release?
Posted
by
Post not yet marked as solved
0 Replies
100 Views
extension UIView { func takeSnapshot(rect : CGRect? = CGRect.zero) -&gt; UIImage? { let renderer = UIGraphicsImageRenderer(size: frame.size) var image = renderer.image { _ in drawHierarchy(in: bounds, afterScreenUpdates: true) } if let imageRect = rect, imageRect != CGRect.zero { let screenshotFrame = CGRect(x: imageRect.origin.x * UIScreen.main.scale, y: imageRect.origin.y * UIScreen.main.scale, width: imageRect.size.width * UIScreen.main.scale, height: imageRect.size.height * UIScreen.main.scale) let imageRef = image.cgImage!.cropping(to: screenshotFrame) image = UIImage.init(cgImage: imageRef!, scale: image.scale, orientation: image.imageOrientation) } UIGraphicsEndImageContext() return image } } which was working fine until I updated to macOS 14.4.1 from 14.2.1 and to Xcode 15.3 from 15.0. issue From my Mac Catalyst app, if I try to take screenshot of imageView, the screenshot is brighter. If I try this method it seems working: func takeSnapshotWithoutScale() -&gt; UIImage? { UIGraphicsBeginImageContextWithOptions(self.frame.size, false, 0) if let currentContext = UIGraphicsGetCurrentContext() { self.layer.render(in: currentContext) } let newImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return newImage }
Posted
by
Post not yet marked as solved
1 Replies
143 Views
I'm trying to get voiceover to announce accessibility label for UIActivityViewController (for a share sheet that pops up on clicking share button) before the focus goes to one of activity items inside the UIActivityViewController. In order to achieve the above behavior, I'm just assigning accessibilityLabel for UIActivityViewController's view. But looks like I'm not able to override the default accessibility implementation of UIActivityViewController. Is there any way we could override the existing accessibility behavior of UIActivityViewController and announce accessibility label for share options? Thanks in advance!!
Posted
by
Post not yet marked as solved
2 Replies
195 Views
Hi all apple devs! I am a young developer who is completely new to everything programming. I am currently trying to develop an app where I want to use visionkit, but I can't for the life of me figure out how to implement its features. I've been stuck on this for several days, so I am now resorting to asking all of you experts for help! Your assistance would be immensely appreciated! I started to develop the app trying to exclusively use swiftUI to futureproof my app. Upon figuring out what visionkit is, to my understanding it is more compatible with UIkit? So I rewrote the part of my code that will use visionkit into a UIkit based view, to simplify the integration of visionkits features. It might just have overcomplicated my code? Can visionkit be easily implemented using only swiftUI? I noticed in the demo on the video tutorial the code is in a viewcontroller not a contentview, is this what makes my image unresponsive? My image is not interactable like her demo in the video, where in my code do I go wrong? Help a noob out! The desired user flow is like this: User selects an image through the "Open camera" or "Open Camera Roll" buttons. Upon selection the UIkit based view opens and the selected image is displayed on it. (This is where I want to implement visionkit features) User interacts with the image by touching on it, if touching on a subject, the subject should be lifted out of the rest of the image and be assigned to the editedImage, which in turn displays only the subject without the background on the contentview. (For now the image is assigned to editedimage by longpressing without any subjectlifting since I cant get visionkit to work as I want) Anyways, here's a code snippet of my peculiar effort to implement subject lifting and visionkit into my app:
Posted
by
Post marked as solved
1 Replies
171 Views
Hi, developers! I use DiffableDataSource for myTableView and was surprised when I found that TableView in this case caches previously created cells after (or before) a new update. It seems that this is implemented to store cell states and quickly update if the contents of the table change. Because of this mechanism, I have the following problem: my cells use reference-type view models, which in turn contain notification observers from the file upload service. The view model is connected to the cell with a closure, which is called upon notification and updates, for example, the progress scale in the cell After uploading the file, I make a new applySnapshot using similar models with cameras (but, for example, the "fileName" field is already different, so I need to change it in cell). Due to caching of cells in memory, the old view models with observers are not released, as a result, I get two observers, for two different cells, one of which is visible, and the second is not. This causes problems with UI. To summarize, my question is, is it possible to disable cell caching or clean the cache if using Diffable Data Source manually?
Posted
by
Post not yet marked as solved
2 Replies
202 Views
I need to create a carousel component with the following requirements (sorted by relevance): Objectives Every image is 16:9 aspect ratio and resizes to fit the screen. Needs a zoom and pan functionality, possibly the same way as iOS Photos app. Needs to work both in landscape and portrait mode, with a smooth transition between orientations. When orientation changes, the image needs to be rotated to preserve the center of the image (like Photos app and hyperoslo/Lightbox) The component should only take the minimum necessary space. In most use cases, such component should have other subviews both above and below. Circularity. I would like the carousel to wrap around. What I tried: Using a TabView with .tabViewStyle(PageTabViewStyle()).indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always)) modifiers. This didn't work: rotating the interface caused the view to get stuck between pages (it looks like it's a well known [bug]).(https://stackoverflow.com/questions/72435939/swiftui-tabview-is-not-working-properly-on-orientation-change). Implementing a single page (that is, an image view) using an UIScrollView and an UIViewRepresentable, then collecting them into an HStack. Unfortunately I need to use zoomScale and contentOffset properties of the UIScrollView outside of the UIViewRepresentable itself. The net result was that .init() was invoked for every image in the carousel at every rotation, causing severe stutters and an horrible rotation animation. Implementing the whole carousel using UIKit, and an UICollectionView, whose cells were an instance of UIScrollView. The problem is, the UIScrollView needs to recompute its constraints upon rotation but a cell is an instance of UIView, so it can't respond to rotations via viewWillTransition(to:CGSize, with: any UIViewControllerTransitionCoordinator). In the UICollectionView itself, you can only access the visible cells (one at a time is visible), and cells are cached, so even after rotating, some occasionally are presented on screen with the same appearance as before the rotation (some do, some don't, in the same UICollectionView). Also when rotating, it looks like the UIScrollView of the visible cell is being recreated, making it impossible to preserve the image center (I use this subclass of UIScrollView for this purpose). And the UICollectionView is taking the full window size, not just the bare minimum necessary space. Help: With all of this in mind, what options do I realistically have? If necessary I can raise the minimum iOS version to 16.0, even though I guess it doesn't make any significative difference since SwiftUI introduced MagnifyGesture only from iOS 17.0.
Posted
by