使用 MKMapView 和可触摸子视图创建视图
是否可以创建一个同时包含 MKMapview 和另一个子视图的视图。特别是我有一个地图视图,并且我一直在尝试添加第二个子视图(到超级视图,而不是 MKMapView)。问题是,虽然两个视图都可以看到,但对 UIView 的任何触摸(不是 MKMapView)都会传递到地图。我什至尝试移动地图,使它们不重叠,但另一个 UIView 相对于地图而不是窗口定位自身。
另一个令人好奇的是,代码在模拟器上运行良好,但在运行 3.1.3 的测试设备上却运行不佳。这可能是 MKMapView 3.1.3 版本的问题,还是模拟器的一个怪癖?
我的代码是
combinedView = [[UIView alloc] initWithFrame:self.view.frame];
self.awView = [[AdWhirlView alloc] init];
awView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
self.awView.delegate = self;
[combinedView addSubview:awView];
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,50,320,430)];
mapView = (MKMapView*)self.view;
mapView.delegate = self;
//[self.view insertSubview:mapView atIndex:0];
[combinedView addSubview:mapView];
//mapView.showsUserLocation = YES;
// Create a location coordinate object
CLLocationCoordinate2D coordinate;
coordinate.latitude = 40.1;
coordinate.longitude = -76.30575;
// Display map
mapView.region = MKCoordinateRegionMakeWithDistance(coordinate, 40000, 40000);
[combinedView bringSubviewToFront:awView];
感谢您的任何建议。
Is it possible to create a view with both an MKMapview and another subview. In particular I have a map view and I have been trying to add a second subview (to the superview, not the MKMapView.) The problem is that while both view can be seen any touches to the UIView that is not the MKMapView pass through to the map. I even tried to move the map so that they do not overlap but the other UIView locates itself relative to the map, not the window.
An additional curiosity is that the code works fine on the simulator, but not on a test device that is running 3.1.3. Could this be a problem with the 3.1.3 version of MKMapView or just a quirk in the simulator?
My code is
combinedView = [[UIView alloc] initWithFrame:self.view.frame];
self.awView = [[AdWhirlView alloc] init];
awView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
self.awView.delegate = self;
[combinedView addSubview:awView];
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,50,320,430)];
mapView = (MKMapView*)self.view;
mapView.delegate = self;
//[self.view insertSubview:mapView atIndex:0];
[combinedView addSubview:mapView];
//mapView.showsUserLocation = YES;
// Create a location coordinate object
CLLocationCoordinate2D coordinate;
coordinate.latitude = 40.1;
coordinate.longitude = -76.30575;
// Display map
mapView.region = MKCoordinateRegionMakeWithDistance(coordinate, 40000, 40000);
[combinedView bringSubviewToFront:awView];
Thanks for any advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对 AdWhirlView 不太熟悉,但是您是否也需要为其设置一个框架?
CGRectMake(0,0,320,50);
还是什么?否则,您可能想使用两个视图的 autoresizeMasks。我确信您可以拥有带有同级视图的 MKMapView,并且它们都工作正常。
Not too familiar with AdWhirlView, but is it possible you need to set a frame for that as well?
CGRectMake(0,0,320,50);
or something?Otherwise, you might want to play with the autoresizeMasks of the two views. I know for certain you can have a MKMapView with sibling views, and they all work fine.