如何在图像而不是地图上放置图钉

时间:2014-06-13 14:12:36

标签: ios objective-c cocoa-touch uikit mapkit

对于我当前的项目,我需要在图像(不是地图)上放置一些引脚,并且还应该能够单击该引脚以向该引脚添加一些注释。我想知道我是否可以使用MKAnnotation / MKAnnotationView来做到这一点。我在互联网上搜索了一段时间。我只找到有关如何使用其他图像自定义MKAnnotation的教程。

如果我不能使用MKAnnotation,我应该使用什么?任何关于此的教程都会非常有用。

感谢。

2 个答案:

答案 0 :(得分:0)

如果要点击图钉,只需在图片视图顶部放置UIButton即可。 MKAnnotationView只能放置在地图视图中。

答案 1 :(得分:0)

你可以这样做:      @property(非原子,强)UIButton *按钮;

 - (void)viewDidLoad
 {
   [super viewDidLoad];
   _button = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
   UIImage *buttonImage = [UIImage imageNamed:@"image.jpg" ];
   [_button setImage:buttonImage forState:UIControlStateNormal];
  UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self     action:@selector(imageTouched:)];
  tapGesture.numberOfTapsRequired = 1;

   [_button addGestureRecognizer:tapGesture];
   [self.view addSubview:_button];
}

 -(IBAction)imageTouched:(UITapGestureRecognizer *)sender
 {
    CGPoint touchedPoint = [sender locationInView:_button];
    UIButton *pin = [[UIButton alloc] initWithFrame:CGRectMake(touchedPoint.x, touchedPoint.y, 10, 10)];
 }

您也可以从故事板链接到当然。 如果您不希望它闪烁/显示用户交互,请为状态UIControlStateHighlighted或UIControlStateSelected设置按钮的图像