在地图上拖动 UIScrollView 时,MKMapView addAnnotation 延迟
我正在开发一个 iPad 应用程序,我有一个全屏 MKMapView,其顶部有一个透明的 UIScrollView(大约屏幕的 1/5)。当您水平滚动 UIScrollView 时,我正在向地图添加注释(地图图钉),但我注意到,在您释放/停止拖动 UIScrollView 之前,图钉实际上不会掉落到地图上。
我还通过添加下面的 NSLog 来确认时间符合预期。当我滚动时,控制台显示“正在添加图钉”消息,但直到您停止拖动才添加图钉。
if(![myMap.annotations containsObject:item]) {
[myMap addAnnotation:item];
NSLog(@"Adding pin."); // Gets called when I would expect, but no pin drops
}
我确信地图正在对触摸执行某些操作,但我不确定如何告诉地图忽略其上方 UIScrollView 中的触摸...或者相反,告诉 UIScrollView 不要将触摸传递给地图如下。
任何帮助将不胜感激。
I'm working on an iPad application and I have a full screen MKMapView with a transparent UIScrollView (about 1/5 of the screen) on top of it. I'm adding annotations (map pins) to the map as you horizontally scroll the UIScrollView, but I'm noticing that the pins don't actually drop onto the map until you release/stop dragging the UIScrollView.
I have also confirmed that the timing is as expected by adding the NSLog below. The console shows the "Adding pin" message when I scroll, but the pin doesn't get added until you stop dragging.
if(![myMap.annotations containsObject:item]) {
[myMap addAnnotation:item];
NSLog(@"Adding pin."); // Gets called when I would expect, but no pin drops
}
I'm sure that the map is doing something with the touches, but I'm not sure how to tell the map to ignore the touches in the UIScrollView above it ... or inversely, tell the UIScrollView NOT to pass the touches to the map below.
Any help would be apprciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过 UIView 上的三个与触摸相关的属性?如果将 UIScrollView 的 .exclusiveTouch 属性设置为 YES,它将阻止触摸事件传递到该窗口中的任何其他视图。
或者您可以将地图视图的 .userInteractionEnabled 属性修改为 NO。无论哪种方式,您都会阻止触摸事件从滚动视图传递到地图视图。
如果这两个属性不起作用,那么您的问题可能与滚动视图内的触摸无关。
Have you tried the three touch-related properties on UIViews? If you set your UIScrollView's .exclusiveTouch property to YES it will block touch events from being delivered to any other view in that window.
Or you could modify the mapview's .userInteractionEnabled property to NO. Either way, you'll block delivery of the touch events from the scroll view to the map view.
If those two properties don't work then your problem is probably something else unrelated to the touching inside the scrollview.