Post

Replies

Boosts

Views

Activity

Setting up keyboard avoidance to a textview using keyboardLayoutGuide
I'm setting up keyboard avoidance to a textview. Objectives: Use keyboardLayoutGuide.followsUndockedKeyboard Allow for floating keyboard on iPad Move the textView up to clear the keyboard when it's tapped Move the textView back when the keyboard is hidden or when the textView is not firstResponder View layout for testing: Three controls. A textField A TextView A UIView The constraint on the bottom of the textView is 15 pts from the top of the UIView. This constraint is set to a Priority of 750 The code I have works fine except when the iPad is rotated. keyboardWillHideNotification fires when the rotation occurs even though the keyboard stays undocked. This causes the textView to drop to its home position and then pop back up again. It's very goofy looking. The textView should hug the top of the keyboard. I tried using textViewDidEndEditing instead of keyboardWillHide but that isn't much better. Anybody have any ideas on making the textView hug the top of the keyboard when the iPad is rotated? class ViewController: UIViewController, UITextViewDelegate { @IBOutlet weak var myTextView: UITextView! private var buttomConstraint: NSLayoutConstraint! override func viewDidLoad() { super.viewDidLoad() myTextView.translatesAutoresizingMaskIntoConstraints = false buttomConstraint = myTextView.bottomAnchor.constraint(equalTo: view.keyboardLayoutGuide.topAnchor) view.keyboardLayoutGuide.followsUndockedKeyboard = true NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) hideKeyboard() } override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { } @objc func keyboardWillHide(notification: NSNotification) { print("Keyboard will hide") if myTextView.isFirstResponder { UIView.animate(withDuration: 0.3) { [weak self] in self?.buttomConstraint.isActive = false self?.view.layoutIfNeeded() } } else { print("Somethibg") } } @objc func keyboardWillShow(notification: NSNotification) { if myTextView.isFirstResponder { UIView.animate(withDuration: 0.3) { [weak self] in self?.buttomConstraint.isActive = true self?.view.layoutIfNeeded() } } else { buttomConstraint.isActive = false } } func textViewDidBeginEditing(_ textView: UITextView) { // UIView.animate(withDuration: 0.3) { [weak self] in // self?.buttomConstraint.isActive = true // self?.view.layoutIfNeeded() // } } func textViewDidEndEditing(_ textView: UITextView) { // UIView.animate(withDuration: 0.3) { [weak self] in // self?.buttomConstraint.isActive = false // self?.view.layoutIfNeeded() // } } } extension ViewController { // MARK: This dismisses the keyBoard when the view it tapped func hideKeyboard() { let tap: UITapGestureRecognizer = UITapGestureRecognizer( target: self, action: #selector(ViewController.dismissKeyboard)) tap.cancelsTouchesInView = false view.addGestureRecognizer(tap) } @objc func dismissKeyboard() { view.endEditing(true) } }
2
0
2.3k
Oct ’22
The firing order of NotificationCenter observing when the keyboard appears and textViewDidBeginEditing has been changed.
If you are seeing the same thing please reply to this post. The firing order was changed when tapping a textView or textField. I first noticed this in iOS 15.6.1 on my physical device. If I send the app to a physical device running iOS 15.5 everything worked fine. Once I updated the device to iOS 15.6.1 or higher the change in firing order broke the ability to get the keyboard height when the textView was first tapped. It's happening on both iPad and iPhone. In Xcode 13.4.1, iOS 15.5 and before. keyboardWillShow fired then textViewDidBeginEditing fired after. This allowed to get the keyboard height before the textView became active and thus move the textView up the proper amount. In Xcode 14.0.1, or anything above iOS 15.5. textViewDidBeginEditing fires then keyboardWillShow fires after. So if you're moving the textview up to clear the keyboard it won't work right anymore because you won't get the keyboard height until after the textView has become firstResponder. The firing order was also changed for textFields. I thought about hard-coding in the keyboard heights for each device but that really doesn't make sense. That and what if Apple changes the keyboard height. I have filed a bug report but so far no response. If you're using notificationCenter to get the keyboard height please check if your app is broken too. If so, please file a bug report so we can get some traction. I have several apps I'm waiting to release and this is holding me up. You can use the code below to check the before and after firing order. Keep in mind that the textView delegate needs to be the view. In viewDidLoad I have this. NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) The selector for NotificationCenter.default.addObserver // MARK: - get the keyboard height @objc func keyboardWillShow(notification: NSNotification) { if let keyboardRectValue = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue { print("keyboardHeight ran \(keyboardHeight)") } } Then I have: // MARK: - TextView Editing Begin. func textViewDidBeginEditing(_ textView: UITextView) { print("textViewDidBeginEditing ran") }
2
1
1.1k
Sep ’22
Editing Did End action is firing when alert opens
I have a textField which opens an alert. The textField is displayed in a custom popup. The textFiled is hooked to Editing_Did_End, Editing_Did_Begin and Editing_Changed actions. I'm running Xcode 13.4.1 In iOS 15.5 everything works fine. In iOS 15.6.1 the Editing_Did_End action is fired as soon as the alert opens. This is causing me a lot of trouble. In iOS 15.5 the Editing_Did_End action is not fired when the alert opens. This is how it has worked in the past. I'm pretty sure this is a bug. Has anybody else run into this? I'd be happy to share my code but the thing is that it works perfectly in iOS 15.5 so I don't think there's a problem with my code.
2
0
1.4k
Aug ’22
Problem with In-App Purchase having 2 status at the same time
This is on an approved app that has an in-app purchase. It was released with hosting turned off which is correct. I did a rev to the app. In the rev I mindlessly changed the in-app purchase and turned hosting on. I thought I was working on a different app. Anyway, I have tried to set it back and turn hosting off but it won't let me save. Now, on the same IAP, I have two status. I thought about deleting the existing IAP and creating a new one but the option to delete is not available. I thought about adding a new IAP and using it but that does not get rid of the Waiting for Upload IAP. Has anybody seen something like this and know how to resolve it. Is there a way to get someone with system level authority to help? Thanks for the help in advance.
1
0
559
Mar ’22
Backwards compatibility with buttons in Xcode 13
I have a number of apps which use a custom tab-bar for navigation. The tab-bar uses buttons with an ICON on top and text below. I have this working in Xcode 12.5 with an extension similar to those below. I wanted to see if I could convert to Xcode 13 and take advantage of the new button configurations. I was having some problems getting this to work properly so I did the following testing. I created a new empty project in Xcode 12.5.1. Closed and re-opened the app in Xcode 13 and added two plain buttons. I didn’t change any of the attributes in the IB so they just have a blue button text. Then I attached one of the extensions below to each button. When the app opens in iSO 15 the buttons display the correct style. However, when either of the buttons is tapped the display reverts back to the text attributes of the button in the IB. So it’s blue, the text reads button and the text size changes back to the default. The ICON and the positioning remain unchanged.  If I create a new Xcode 13 project and do the exact same thing then everything working fine. Is anybody else seeing this? Is there something I need to change something in the extensions to make it work in pre 13 Xcode? @available(iOS 15.0, *) extension UIButton {     func settings_MenuBtn()     {         self.configuration = .plain()         let imageConfig = UIImage.SymbolConfiguration(scale: .large)         self.configuration?.title = "Settings"         self.configuration?.attributedTitle?.foregroundColor = .white         self.configuration?.imagePlacement = .top         self.configuration?.titleAlignment = .center         self.configuration?.imagePadding = 6         self.configuration?.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)         self.configuration?.image = UIImage(systemName: "gearshape", withConfiguration: imageConfig)                  self.configuration?.attributedTitle?.font = .systemFont(ofSize: gMenuTextSize, weight: .regular)     } } @available(iOS 15.0, *) extension UIButton.Configuration {     static func settings_MenuBtn2() -> UIButton.Configuration     {         let imageConfig = UIImage.SymbolConfiguration(scale: .large)         var config: UIButton.Configuration = .plain()         config.title = "Settings"         config.attributedTitle?.foregroundColor = .white         config.attributedTitle?.font = .systemFont(ofSize: gMenuTextSize, weight: .regular)         config.image = UIImage(systemName: "gearshape", withConfiguration: imageConfig)         config.imagePlacement = .top         config.titleAlignment = .center         config.imagePadding = 6         config.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)         return config     } }
3
0
1.1k
Oct ’21
invalid mode 'kCFRunLoopCommonModes'
invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debugI get this warning when I tap either of the switches shown below. I've tried capturing the switch state in a var and using that to trigger the do/catch statement but no joy. I've even tried pulling the do/catch into separate functions and I still get the warning. Has anybody else run into this and how did you fix it?@IBAction func greetingFormat_Tapped(_ sender: UISwitch) { let theQuery = theTable_Settings.filter(settingID == 1) if sender.isOn { do { if try Database.shared.databaseConnection!.run(theQuery.update(greeting_Format <- "true")) > 0 { greetingFormatLabel_Outlet.text = NSLocalizedString("HelloMrSmith_String", comment: "") } else { print("greeting format true not found") } } catch { print("greeting format true update failed! Error: \(error)") } } else { do { if try Database.shared.databaseConnection!.run(theQuery.update(greeting_Format <- "false")) > 0 { greetingFormatLabel_Outlet.text = NSLocalizedString("HiJoe_String", comment: "") } else { print("greeting format false not found") } } catch { print("greeting format false update failed! Error: \(error)") } } }@IBAction func nonrefundableSwitch_Tapped(_ sender: UISwitch) { let theQuery = theTable_Settings.filter(settingID == 1) var itsOn: String = "" if sender.isOn { itsOn = "true" } else { itsOn = "false" } if itsOn == "true" { do { if try Database.shared.databaseConnection!.run(theQuery.update(nonRefundable_Bool <- "true")) > 0 { depositDueLabel_Outlet.text = NSLocalizedString("nonRefunddepositisdue_String", comment: "") } else { print("nonRefundable true not found") } } catch { print("nonRefundable true update failed! Error: \(error)") } } else { do { if try Database.shared.databaseConnection!.run(theQuery.update(nonRefundable_Bool <- "false")) > 0 { depositDueLabel_Outlet.text = NSLocalizedString("depositisdue_String", comment: "") } else { print("nonRefundable false not found") } } catch { print("nonRefundable false update failed! Error: \(error)") } } }
34
2
24k
Apr ’20