When a real device is connected to my Mac and while running it, the behaviour of UIMenuController appears to be correct. That is, copy/cut actions aren't displayed for empty text field. Whereas, after stopping the run, and relaunching it once again: the menu controller for empty textfield contains cut/copy and other actions as well.
When we have an empty textfield => only paste option should be visible.
When we have a non-empty textfield => cut/copy/paste all options should be visible.
Related
I've taken over the work on an iOS app, I've managed to work quite well with it thus far adding new functionality despite not being a trained iOS developer. However I've hit a patch where I simply cannot get the keyboard to show on screen when I tap on a UITextfield, there are areas of the app where it works but any new areas I add this simply will not work. Is there a standard bit of code that controls showing the keyboard when you tap a text field?
Need help
Keyboard opens up automatically unless you forced to not open.
You can check following, See screenshots.
Enable is checked
User Interaction Enable is checked
If you are checking on simulator try “command + k” from keypad
textFieldShouldBeginEditing delegate returns TRUE
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
return TRUE;
}
Are you running on a simulator or a real device?
When I use an iOS device for debugging, I can type and retype into the search bar at the top (I am running a webkit browser inside my app). If I do this in the emulator I can type in it when the search bar is empty but after I have search for something and it is filled with a URL, I cannot retype into it as the search bar moves back and forth when I try to select it.
It works perfectly fine on an actual iOS device but on the emulator it will toggle.
It uses the basic webkit library: https://en.wikipedia.org/wiki/WebKit
I expect it to work like on the iOS device and it does if I toggle the software keyboard but without it, it doesn't.
From the engineer who fixed it:
It's actually strange. I'm not sure if this PR is relying on an undocumented behaviour, but it should be safe even if that changes. Here's what's happening.
iOS should fire UIResponder.keyboardWillShowNotification when the keyboard is going to be displayed, and UIResponder.keyboardWillHideNotification when the keyboard is going to be hidden. For both notifications, this code retrieves the frame of the keyboard:
let beginRect = (notification.userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue
let endRect = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
What's strange is that in the iOS simulator, if the software keyboard is toggled off (so simulating an external keyboard), UIResponder.keyboardWillShowNotification is never fired (which is understandable) and UIResponder.keyboardWillHideNotification is fired both when a text box becomes first responder (i.e. gains focus) and when the textbox resigns first responder (i.e. loses focus). I guess the rationale is that these notifications are fired for the software keyboard and in both cases the keyboard is hidden. Empirically, in iOS 12 (and iPhone X):
A. When a text box becomes first responder, beginRect.size.height=0 and endRect.size.height ~54. Both origin.y remains at ~812 (out of the screen).
B. When a text box resigns first responder, beginRect.size.height ~54 and endRect.size.height=0. Both origin.y remains at ~812 (out of the screen).
The fix is to test for A and ignore it when handling UIResponder.keyboardWillHideNotification
"Manual" alerts work fine with text fields and dismiss keyboards when an action is clicked.
With SDCAlertView the text fields are not dismissed.
Have not updated to Swift 4. Kept everything as is. Only running on iOS 11.
Eg. from the demo project: http://file.5ep4r0.com/fAMsWuV.mp4
Thanks
I am using XCTest to test my IOS app.
As part of a test case I need to enter a number into a field (which is not a text box)
When I record the test, following code is generated when I use the soft keyboard on the simulator(IPAD/IPhone)
app.staticTexts["0"].tap() //Line 1
app.typeText("23") //Line 2
When I execute the test, the soft keyboard pops up after Line 1. But when Line 2 is executed, following error appears
UI Testing Failure - Neither element nor any descendant has keyboard focus
My app requires to be installed on IPads/IPhones. So I need to make it run through the soft keyboard route only.
So I think typeText is not the correct method. What is the method to simulate clicks on a soft/virtual keyboard in an IOS simulator?
You need to call typeText() on the element with keyboard focus, not just app.
If the element was a text field, you would find the text field element and call typeText() on that.
let element = app.textFields["myTextField"]
element.typeText("23")
You will need to replace the query with your own one for finding the element which has keyboard focus. Usually, this would be a descendant of UITextField but you will need to use a more custom query if you are using a custom view instead.
I have a ios8 project in XCode 6.1 using size classes. At somepoint in development, the Keyboard stopped displaying while editing a UITextField. To debug, I made simple UIViewController with a single UITextField in a different storyboard in the project, and the keyboard would not display for that UITextField either.
I then made an entirely new project and a simple UIViewController and a single UITextField and the keyboard DID work correctly.
I've looked at all the settings in the project and could find nothing that looks like it affects the keyboard.
Any ideas on what is going on?
If this happen only in the simulator then go to
Hardware Menu->Keyboard->Toggle Software Keyboard
or use shortcut key
cmd+k
Go to simulator -> Hardware then
then click on Toggle Softwate Kwyboard, then you will get key board for TextField