How to make UITextView register touches when it is currently first responder? - ios

I need a way to know when a UITextView is touched while it is first responder. I have seen some threads about this but I have never figured out how to make it work. I'm assuming there must be a way? Any input would be much appreciated thanks!
rc

UITextField is a subclass of UIControl, so you can add yourself as listener for events using addTarget:action:forControlEvents:.

Related

UIScrollView pass event to child chain on WillEndDragging

Edit: I am editing my initial question (see below for history) as I am getting new information.
I figured out that when the swipe motion starts from inside the button bounds, we never receive TouchesEnded or TouchesCancelled, only TouchesMoved. However, if I can react on WillEnddragging, it would be great. Is it possible to cancel a gesture on WillEndDragging and also pass this cancel down the children chain?
History:
I am using Xamarin Forms and I have the following issue
I have custom controls part of native scrolling views, like ScrollView or CollectionView, that remain in "clicked" state after the finger enters them but then initiates a scroll gesture.
I had a similar issue on UWP in the past and managed to solve it with the UIElement.PointerCaptureLost event.
Sorry if I am wasting your time on trivial stuff, but I am really stuck and I greatly appreciate your help.
I have tried different approaches suggested, including setting DelaysContentTouches to NO, and playing around with CanCancelContentTouches and overriding TouchesShouldCancelInContentView to always return NO, in a ScrollView custom renderer.
I have had a read of
Allow UIScrollView and its subviews to both respond to a touch
and
UIScrollView sending touches to subviews
Maybe the accepted answer here helps, but I am not sure how to get the tag of my custom view.
What I am expecting is my custom controls to receive the cancelled touch event (or something similar) as happens in both Android and Windows
This was easier than it looked. Solved by adding a UIGestureRecognizerDelegate to my UIGestureRecognizer class and in the delegate I overwrote ShouldRecognizeSimultaneously to return true.

[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.

Any way to know if UITextField is in the view's hierarchy?

I am creating a UITextField-A inside an inputAccessoryView and when I call [UITextField-A becomeFirstResponder], it would not work. However, if I do it with a delay of 1 sec, it would work. From what I searched, it is because the UITextField is not in the view's hierarchy yet. So is there a way to know so I do not need to use the 1sec delay alternative? Is there a UITextFieldDidAppearInViewHierarchy or somekind in the SDK?
UIView offers a didMoveToSuperview method that you could abuse to do this.

Using tableView:didDeselectRowAtIndexPath: to edit a UITextField in a cell

How would you use tableView:didDeselectRowAtIndexPath: to trigger textFieldShouldBeginEditing: ?
Or what other options do I have? I did consider having tableView:didDeselectRowAtIndexPath: trigger a UIAlertView (with textField) but it isn't aesthetically pleasing.
Your question is a little light on details: what's the user interface look like? What are you tying to accomplish?
To literally answer your question, you can just have didDeselectRowAtIndexPath implementation call the method textFieldShouldBeginEditing - however I don't believe that's what you're asking? What it sounds like you're asking is how you can get a touch event on a table view cell to pass into a UITextField so that editing begins.
That would make this a duplicate of other questions already asked here:
Having a UITextField in a UITableViewCell
Not sure how proper the practice is, but I have an app I use a textField that is 1x1 points and off screen. If I want to bring up the keyboard, I call
[self.myTextField becomeFirstResponder];
Then you can use the UITextFieldDelegate methods to control and update information being entered on the keyboard.
Then when the user is done, I call
[self.myTextField resignFirstResponder];
Of course this is assuming that you don't actually want to use a textField in your tableView.
Hope this helps.

UIwebview does not respond to touchesBegan

I have subclass of UIViewController which has UIWebview as a subview added.
I'm trying to detect touch events on webview but failing to do so.
-(void)touchesBegan
is the method which should get called.
Can anyone help me in this.
Thanks in advance.
Detecting touches on UIWebView is not trivial.
Check this tutorial : http://mithin.in/2009/08/26/detecting-taps-and-events-on-uiwebview-the-right-way/
BTW - If you need only to detect a touch on a links or buttons and add a custom action you can do it to. look here:
http://dblog.com.au/iphone-development/iphone-sdk-tip-firing-custom-events-when-a-link-is-clicked-in-a-uiwebview/
Good Luck
Make sure your UIWebView is the first responder. When you add it, use becomeFirstResponder on the web view (I've linked the documentation at Apple for you).
Also make sure becomeFirstResponder returns YES.
Lastly, make sure your view controller's UIView userInteractionEnabled property is set to YES.

Resources