UIStepper swallows the touch - ios

I'm using an UIStepper to change a value that is displayed in a UITextField, with the option of being editable entering the value in the UITextField.
Everything works fine, but there is a undesired behavior: the UITextField can only be edited pressing the upper half of the object itself, because the touch in the lower half is swallowed by the UIStepper.
I've looking for an answer, but I haven't find any. I have some hint though.
UIStepper has 2 buttons and 1 ImageView, and the touch is detected in the entire ImageView (not visible or editable).
Any ideas?

To fix this would most likely require subclassing. You can override pointInside:withEvent: in a UIStepper subclass and return NO unless strictly within the bounds of the stepper:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
return CGRectContainsPoint(self.bounds, point);
}

One option is to put both the stepper and the text field inside a container view that overrides -hitTest:withEvent: such that it queries the text field before querying the stepper. If the text field says that it's hit, return a pointer to the text field. If not, check the stepper and return that if it says it's hit.
Controls sometimes pretend to be larger than they are so that they're easier to touch. Using the preceding technique should let you keep as much of the stepper's extra touchable area as possible without hindering use of the text view.

Related

Custom Keyboard extension with UITextField

I have custom keyboard extension with UITextField in it. I am able switch to UITextField's text input, but cannot switch back to self.textDocumentProxy. Does anybody know, how to do something like [self.textDocumentProxy becomeFirstResponder]?
(By the way, it looks like "GIF Keyboard" app provides such possibility)
I've implemented next workaround for this:
My textFied inherits from UITextField. UserInteraction disabled to prevent it from becomeFirstResponder (because you are not able switch back to system input). I've added blinking UIView as cursor imitation (blinking animation). Change this cursor origin.x in overwrited setText: method by calculating length of current string (use boundingRectWithSize: method for this).
When user types something I am checking if textField is active (showed) and then adding/removing symbols to textField (with setText:) or self.textDocumentProxy insertText:/deleteBackward methods accordingly.

iOS Custom keyboard can't return focus to app's textfield

I'm working on a custom keyboard for iOS which will have its own search field (similarly implemented by PopKey).
My keyboard's textfield is able to take the focus with becomeFirstResponder and I'm able to give it up by using resignFirstResponder. However after I resign focus, the host app has a difficult time retaking focus despite touching the form. The app's textfield will still show the text cursor blinking.
Any ideas? Thanks
The solution is a hack, as of right now you can't really give the host app its focus back.
Subclass a UITextField and on its delegate implement
textFieldShouldBeginEditing by returning NO.
Add a BOOL property isSelected that gets set to YES in touchesBegan (not to be confused with the default selected property)
In your keyboard's keyPressed method, if searchField.isSelected, manipulate the searchField.text. Else, manipulate textDocumentProxy like normal.
Add a clear button and method that wipes searchField.text and searchField.isSelected, allowing any further keystrokes to return to the textDocumentProxy
Add an animation that replicates the blinking type cursor

[Objective-C]Edit UILabel without hiding keyboard

Im trying to copy the content in a UILabel but without hiding the keyboard, the problem is that when I show the menu of copy in the label the label becomes first responder and the keyboard resign, but I want to do that without hiding the keyboard, is there a way to do that?
It is not possible with UILabel.
You should use UITextField for that. Just disable editing.
AFAIK, you can't do that. But I think you can have a work around for that. Instead of not hiding the keyboard, why don't keep track the current active text field and then active it after user press copy. You can use UIPasteboardChangedNotification to know when user pressed copy. For example:
self.lastActiveTextField = aTextField
-(void)pasteBoardDidChange:(NSNotification*)notif
{
[self.lastActiveTextField becomeFirstResponder];
}
I think so u r looking something like this project.
UILabel with UIKeyInput protocol implementation
https://github.com/hackiftekhar/IQEditableLabel
I think, it is not possible, there can be only one first responder at any time. If the keyboard is shown because of another UI element, then when you try to copy the content from UILabel, the OS has to transfer first responder from other element to UILabel, as there is no need of keyboard for UILabel, the keyboard will hide automatically. So, you have to make changes to your elements to fix this problem or use third party UI elements who can fix your problem.
Every UIView component has a method called: canBecomeFirstResponder. He is read only, but you can subclass the UI object and override the getter:
- (BOOL)canBecomeFirstResponder {
return false;
}
I didn't do the test, but if the "become first responder" is the problem, that should solve it.

Touch Down/Up and Scroll in UITableViewController

I'm having a bit of of a pain point in figuring something out.
I have a uitableviewcontroller, and each cell is static. Inside each cell is a textbox. When the user TAPS on a textbox, I'd like an event to fire.
So while I'd like my table to still scroll, i'd also like tap events to work when you tape the textbox.
Apparently in uitableviews, they add a delay to your tap so you have to hold your finger down for a second or so for 'tap' to register. I felt this was not intuitive to a user, so I did this to fix it:
for subview in self.tableView.subviews as [UIView]
{
if subview is UIScrollView
{
let scroll = subview as UIScrollView
scroll.delaysContentTouches = false
break
}
}
This works perfectly, and now when I tap my textbox, it instantly executes my tap event! The problem now, however, is some of my textboxes are positioned right where a user would naturally scroll. When they put their finger down (touch down event) to scroll, it's unfortunately being intercepted by the tap event, and prevents scrolling and instead executes my event.
What i'd really want is if the user puts their finger down, and then swipes, it doesn't execute the touch down event. I thought to be clever and switch touch down to touch up, but when I put my finger down and then pick it back up, it does nothing (touch up inside seems to do nothing). I read this was because it only works on buttons and things like that, and not textfields. So, yes, now I can scroll without my action, but when I tap the textbox and lift my finger up it doesn't execute that, either.
Any ideas on how to either
1) permit touch downs and scrolling to co-exist without having to hold my finger down for a second and deal with that delayContentTouches?
2) somehow get a tap up inside event to fire when I tap on a textbox?
I saw some info here but didn't seem to help much:
UIButton inside UITableViewCell steals touch from UITableView
Thanks!
Well, as luck would have it, I was able to figure this out. Would love some criticism/advice if something might not be ideal here, but what I did was add this to my subclassed textfield:
override func canBecomeFirstResponder() -> Bool {
performMyFunctionHere()
return false
}
So I am returning false on first responder which prevents any sort of keyboard appearing (which is what I wanted) and instead using performMyFunctionHere() I can do what I wanted to do (in my case, make an action sheet picker appear). I assign the action sheet picker in my view controller and assign it to each specific instance of my subclassed uitextfield. Nothing really complicated, to be honest. I'm surprised this works as well as it does.
By the way one thing that didn't seem extremely important was setting the delaysContentTouches as I mentioned above. I guess because now it's using the responder it will always work? It didn't seem to matter whether I removed it or not, but would love thoughts on whether it's better to leave it in or not.
Thanks!

manipulating the keyboard: change frame, edit text field other than the one tapped

I'm having trouble finding info on manipulating the keyboard. Here's what I want to do:
When the user touches a text field, I want a keyboard to appear. However:
1) I want to move the keyboard up 30 pixels so that another view is visible south of it.
2) The keyboard should not actually edit the text field the user touched. A multiline text view will be presented for the user to edit instead.
I'm not sure of the best strategy and I don't know the methods I'll need to use or properties I'll need to set. Some sample code would be greatly appreciated.
As #HenryHarris says, you can't move the keyboard (or more appropriately shouldn't, as Apple expects it to be where they put it and will most likely reject your app if you start messing with it).
You can on the other hand, switch to a different view when they tap the text field by using something like this:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
// Present your text view, let's call it myTextView for now, and then tell it to start accepting input:
[myTextView becomeFirstResponder];
// Now return NO so that the textField does NOT become the first responder:
return NO;
}

Resources