简体   繁体   English

UIView中的UITextField没有响应用户交互

[英]UITextField within UIView not responding to user interaction

Here's my scenario: 这是我的情景:

I have a UIViewController in my StoryBoard for my mapping feature. 我的StoryBoard中有一个UIViewController用于我的映射功能。 I'm adding a Google Map view (GoogleMaps iOS 1.3.1) like: 我正在添加Google地图视图(GoogleMaps iOS 1.3.1),例如:

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_;

I created a custom view: MapTopBar.xib. 我创建了一个自定义视图:MapTopBar.xib。 Simply put, it's a UIView with an UIImageView (background) and a UITextField & Button. 简单地说,它是一个带有UIImageView (背景)和UITextField &Button的UIView It has a backing class file and all of the UITextFields properties have been set (delegate, outlets, etc). 它有一个支持类文件,并且已设置了所有UITextFields属性(委托,出口等)。

I'm adding my custom view to my Map VC like: 我将我的自定义视图添加到我的Map VC中,如:

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

My custom view is being added to the main view, but the UITextField is not receiving any touch events. 我的自定义视图正被添加到主视图中,但UITextField未接收任何触摸事件。 The keyboard is not being displayed, no cursor in the field, nothing. 键盘没有显示,字段中没有光标,没有。 It's as if something is covering it up, not allowing any user interaction. 好像有什么东西掩盖了它,不允许任何用户交互。 The button next to it can be pressed and works fine. 可以按下它旁边的按钮并正常工作。

I've tried doing this many different ways (creating the entire topBar view programmatically, adding the text field programmatically) and no matter what, the text field will not get user interaction. 我尝试过这么多种方式(以编程方式创建整个topBar视图,以编程方式添加文本字段),无论如何,文本字段都不会获得用户交互。

I've enabled user interaction, made sure no view was on top of the text field, all for null. 我启用了用户交互,确保没有视图位于文本字段之上,全部为null。 I feel like I'm missing something simple. 我觉得我错过了一些简单的事情。 Why can't I interact with my textfield? 为什么我不能与我的文本域互动?

Also: in case it's relevant, the code above is within it's own sub being called from the viewDidLoad before the super call. 另外:如果它是相关的,上面的代码是在超级调用之前从viewDidLoad调用它自己的子代码。

It seems likely that the UITextField is outside the bounds of its parent view, and not being clipped. UITextField似乎超出了其父视图的范围,并且没有被剪裁。 (Or the parent view is outside the bounds of its parent... etc.) (或者父视图超出其父视图的范围......等等)

In viewDidAppear, use the debugger or NSLog the view hierarchy that ends in your UITextField. 在viewDidAppear中,使用调试器或NSLog以UITextField结尾的视图层次结构。 Check to ensure that the frames of each view are fully within their parent view. 检查以确保每个视图的帧完全位于其父视图中。

Something like this should do the trick to identify any out-of-frame views: 像这样的东西应该可以识别任何帧外视图:

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

I have the same issue! 我有同样的问题! Have you found any work around? 你找到了解决方法吗? Seems that everything is ok with UITextField's frame. 似乎UITextField的框架一切正常。 For debug purpose I've put a button above the UITextField and this button was able to get touches. 出于调试目的,我在UITextField上面放了一个按钮,这个按钮能够触及。 Maybe the deal is in the way the Google map view handles touches or ui drawing? 也许这笔交易与Google地图视图处理触摸或ui绘图的方式有关?

确保将文本字段插入内容视图。

I had this same problem and found a solution here https://stackoverflow.com/questions/20015266 我遇到了同样的问题,并在此处找到了解决方案https://stackoverflow.com/questions/20015266

It seems GMSMapView has a BlockingGestureRecognizer which prevents the interaction with the text field. 似乎GMSMapView有一个BlockingGestureRecognizer,它阻止了与文本字段的交互。 If you disable this keep in mind that the parent views will receive the events from the gestures 如果禁用此功能,请记住父视图将从手势中接收事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM