我有一个包含许多其他子视图的UIScrollView。大多数子视图都是UITextView的,当它们全部加载时,滚动和一切都很好。但是对于其中一个视图,我正在加载一个带有MKMapView和UITextView的视图。当用户想滚动UIScrollView时,他们不能触摸UIView或其内容。我不能将setUserInteractionEnabled设置为NO,因为我需要用户能够单击MKMapView,然后转到另一个UIViewController进行地图。对此有什么建议吗?我有下面的代码:
CGRect dealDescRect = CGRectMake(10, 10, delegate.scrollView.frame.size.width - 22 - 20, 120);
mapView = [[MKMapView alloc] initWithFrame:dealDescRect];
mapView.layer.cornerRadius = cornerRadius;
mapView.scrollEnabled = NO;
mapView.zoomEnabled = NO;
BOOL result = [self loadAddressIntoMap];
if (result == TRUE) {
UITapGestureRecognizer* recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[mapView addGestureRecognizer:recognizer];
}
UITextView *addressTextView = [self generateTextView:addressText :5];
addressTextView.editable = NO;
[addressTextView setFont:[UIFont systemFontOfSize:fontSize]];
[addressTextView setUserInteractionEnabled:NO];
CGRect addressTextViewFrame = addressTextView.frame;
addressTextViewFrame.origin.x = 0;
addressTextViewFrame.origin.y = 130;
addressTextViewFrame.size.height = addressTextView.contentSize.height + 15;
addressTextView.frame = addressTextViewFrame;
CGRect viewRect = CGRectMake(10, 145, delegate.scrollView.frame.size.width - 22, addressTextView.contentSize.height + 135);
viewRect.origin.x = 11;
viewRect.origin.y = startTop;
UIView *view = [[UIView alloc] initWithFrame:viewRect];
view.layer.cornerRadius = cornerRadius;
[view setBackgroundColor:[UIColor whiteColor]];
[view addSubview:mapView];
[view addSubview:addressTextView];编辑
由于一些奇怪的原因,如果我将UIView更改为UITextView,它就能工作!不过,不知道真正的解决方案是什么。我只是停止编辑。
发布于 2013-03-23 16:44:21
如果是我,而不是使用手势识别器来监视地图上的点击,我会创建一个自定义类型的UIButton (UIButtonTypeCustom),给它没有背景和文本,并将它放在地图的顶部,与地图的帧相同。
这样做的好处是防止用户与地图交互,按您的意愿移动到下一页,如果用户开始滚动,即使在地图上他们能够滚动。
https://stackoverflow.com/questions/15588620
复制相似问题