【发布时间】:2011-06-09 11:15:33
【问题描述】:
当我单击带有导航按钮的注释按钮以返回到我的 mapkit 并将一些参数传递给视图时,如何打开视图?
问候
【问题讨论】:
-
像在任何地方一样导航到另一个视图。从包含 mkmapview 的视图移动没有什么特别的。
标签: xcode annotations mapkit callouts
当我单击带有导航按钮的注释按钮以返回到我的 mapkit 并将一些参数传递给视图时,如何打开视图?
问候
【问题讨论】:
标签: xcode annotations mapkit callouts
我找到了解决办法。内部:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
添加:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[btn addTarget:self action:@selector(pinTouched:) forControlEvents:UIControlEventTouchUpInside];
然后有一个函数可以打开想要的视图:
-(void)pinTouched:(UIButton *)sender
{
myView.transform = CGAffineTransformMakeScale(.01, .01);
[self.view addSubview:myView];
}
【讨论】:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
... ... ...
//重要
//否则calloutAccessoryControlTapped不被调用
pin.canShowCallout = YES;
pin.calloutOffset = CGPointMake(-10, -10);
UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"some.png"]];
leftIconView.backgroundColor = [UIColor clearColor];
leftIconView.contentMode = UIViewContentModeScaleAspectFit;
leftIconView.frame = CGRectMake(0, 0, 40, 40);
pin.leftCalloutAccessoryView = leftIconView;
....
....
返回针;
}
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// 已点击注释
浮动 viewWidth = 100;
浮动 viewHeight = 300;
浮动视图X = 50;
浮动视图Y = 50;
CGRect viewRect = CGRectMake(viewX,viewY, viewWidth, viewHeight);
UIView *viewSub = [[UIView alloc] initWithFrame:viewRect];
viewSub.backgroundColor = [UIColor redColor];
viewSub.tag = 666;
[self.view addSubview:viewSub];
[self.view bringSubviewToFront:viewSub];
}
【讨论】: