我需要在所有其他注释之上绘制当前用户注释(蓝点).现在它正在我的其他注释下面被隐藏起来.我想调整此注释视图的z-index(蓝点)并将其置于顶部,有人知道如何吗?
更新: 所以我现在可以处理MKUserLocationView,但我该如何推进呢?
- (void) mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views {
for (MKAnnotationView *view in views) {
if ([[view annotation] isKindOfClass:[MKUserLocation class]]) {
// How do I bring this view to the front of all other annotations?
// [???? bringSubviewToFront:????];
}
}
}
Run Code Online (Sandbox Code Playgroud) 我需要在地图中适应某些边界.我得到了调用谷歌地理编码器和阅读视口属性的界限,如下所示:
{
northeast = {
lat = "30.4212235";
lng = "-97.486942";
};
southwest = {
lat = "30.1128403";
lng = "-97.99917959999999";
};
}
Run Code Online (Sandbox Code Playgroud)
然后我将它们转换为CLLocationCoordinate2D
NSDictionary *viewport = [[[results objectAtIndex:0] objectForKey:@"geometry"]
objectForKey:@"viewport"];
NSDictionary *NEDictionary = [viewport objectForKey:@"northeast"];
NSDictionary *SWDictionary = [viewport objectForKey:@"southwest"];
CLLocationCoordinate2D SWCoordinate =
CLLocationCoordinate2DMake(
[[SWDictionary objectForKey:@"lat"] floatValue],
[[SWDictionary objectForKey:@"lng"] floatValue]
);
CLLocationCoordinate2D NECoordinate =
CLLocationCoordinate2DMake(
[[NEDictionary objectForKey:@"lat"] floatValue],
[[NEDictionary objectForKey:@"lng"] floatValue]
);
Run Code Online (Sandbox Code Playgroud)
我知道我需要从这些坐标生成MKMapRect(或MKMapRegion,哪个更容易)然后[mapView setVisibleRect:newRect animated:YES](或[mapView setRegion:newRegion animated:YES]但我不太确定如何到达那里.我需要一种方法将边界转换为适当的数据结构,如:
- (MKMapRect) mapRectThatFitsBoundsSW:(CLLocationCoordinate2D)sw
NE:(CLLocationCoordinate2D)ne {
// CGFloat x = ??
// CGFloat …Run Code Online (Sandbox Code Playgroud) 我有一个tabbar应用程序,在其中一个选项卡中我有一个MKMapView.在这个视图中,我的viewDidLoad我正在为UIButton初始化一个长按手势识别器.按下此按钮并帮助它显示带有5个按钮+取消按钮的UIActionSheet.每个按钮代表一个缩放级别:"世界","国家","州","城市","当前位置".选择UIActionSheet中的按钮可将基础MKMapView缩放到该级别.
我遇到的问题是所有按钮(包括取消按钮)都需要双击才能关闭UIActionSheet.这不是预期的行为 - 它应该像按下每个其他UIActionSheet一样按下按钮后解除.第一次按下后,我可以看到地图缩放到UIActionSheet后面的适当级别,所以我知道触摸正在正确的按钮上注册,但是第一次按下时按钮不会突出显示蓝色,并且UIActionSheet不会消失.直到我第二次按下按钮,它才会突出显示蓝色然后消除.
如果我删除了长按手势识别器并将UIActionSheet呈现在"内部触摸"上,那么一切都按预期工作.所以我知道这个手势是以某种方式干扰,任何关于修复或解决方法的想法?或者这是一个应该向Apple报告的错误?
- (void) viewDidLoad {
// intitialize longpress gesture
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(zoomOptions:)];
longPressRecognizer.minimumPressDuration = 0.5;
longPressRecognizer.numberOfTouchesRequired = 1;
[self.currentLocationButton addGestureRecognizer:longPressRecognizer];
}
- (IBAction) zoomOptions:(UIGestureRecognizer *)sender {
NSString *title = @"Zoom to:";
UIActionSheet *zoomOptionsSheet = [[UIActionSheet alloc] initWithTitle:title delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"World", @"Country", @"State", @"City", @"Current Location", nil];
[zoomOptionsSheet showFromTabBar:appDelegate.tabbarController.tabBar];
}
Run Code Online (Sandbox Code Playgroud) 我需要在iOS中创建一个圆形评级表,它就像一个UISlider只绕圆圈弯曲3/4.我需要在一个锚点周围旋转一个UIImageView(它是一个评级针),通过拖动一个看不见的可触摸手柄区域,它将跟随针尖.针的角度将确定一个值.
我正在努力寻找一个优雅的解决方案.有什么想法吗?