UITextField in UIView does not respond to user interaction

Here is my scenario:

I have a UIViewController in my StoryBoard for my display function. I am adding a Google Map view (GoogleMaps iOS 1.3.1), for example:

 GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 longitude:151.20 zoom:6]; mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 49, 320, 450) camera:camera]; mapView_.myLocationEnabled = YES; self.view = mapView_; 

Created a custom view: MapTopBar.xib. Simply put, this is a UIView with a UIImageView (background) and a UITextField and Button. It has a support class file and all UITextFields properties are set (delegate, outputs, etc.).

I am adding my custom view to my VC map, for example:

 UIView *topBar = [[MapTopBar alloc] initWithFrame:CGRectMake(0, 0, 320, 49)]; [self.view addSubview:topBar]; 

My custom view is added to the main view, but the UITextField does not receive any touch events. The keyboard is not displayed, there is no cursor in the field, nothing. It is as if something is covering him, not allowing him to interact with the user. The button next to it can be pressed and works fine.

I tried to do this in different ways (creating a full topBar view programmatically, adding a text box programmatically), and regardless of whether the text box will not interact with the user.

I turned on user interaction, make sure there was no view above the text box, all for zero. I feel that I am missing something simple. Why can't I interact with my text box?

Also: in case it matters, the code above is inside it, and its sub-call is called from viewDidLoad before the super-call.

+4
source share
4 answers

It seems likely that a UITextField goes beyond its parent view and is not cropped. (Or the parent view is outside of its parent ... etc.)

In viewDidAppear, use a debugger or NSLog view hierarchy that ends on your UITextField. Make sure that the frames of each view are completely within their parent view.

Something like this should do the trick to identify any off-frame views:

 UIView* v = _myTextField; while ( v.superview != nil ) { NSLog( @"%@ - %@", NSStringFromClass([v class]), CGRectContainsRect( v.superview.bounds, v.frame ) ? @"GOOD!" : @"BAD!" ); v = v.superview; } 
+1
source

I have the same problem! Did you find any work? Everything seems to be ok with the UITextField frame. For the purpose of debugging, I set the button above the UITextField, and this button was able to get the strokes. Maybe the deal is how the look of the google map handles the touches or the ui drawing?

0
source

Make sure you paste the text box into the content view.

0
source

I had the same problem and found a solution here fooobar.com/questions/1489168 / ...

GMSMapView seems to have a BlockingGestureRecognizer that prevents interaction with the text box. If you disable this, keep in mind that parent views will receive events from gestures.

0
source

Source: https://habr.com/ru/post/1489165/


All Articles