OStack程序员社区-中国程序员成长平台

标题: ios - 没有获得按钮操作/单击自定义 MKannotation 调用 View [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 19:12
标题: ios - 没有获得按钮操作/单击自定义 MKannotation 调用 View

我为我的 map View 创建了自定义注释和标注。当用户单击标注 View 或单击添加为标注 View 的 subview 的按钮时,我需要导航到另一个 View 。但是在这种情况下,手势识别器和添加目标都不适合我。 setSelected: 方法被调用,当在调用 View 中点击时 View 被隐藏。

 @interface VBPunchCardAnnotation : MKAnnotationView{

    UIView *calloutView;
  }

- (id)initWithAnnotationid )annotation reuseIdentifierNSString *)reuseIdentifier dealid)punchdeal
{
  self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
  calloutView = [[UIView alloc] init];
  calloutView.hidden = YES;

  infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];

  [calloutView addSubview:infoButton];

  UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self actionselector(annotationTapped];
  singleTap.numberOfTapsRequired = 1;
  singleTap.delegate = self;
  [calloutView addGestureRecognizer:singleTap];

  [infoButton addTarget:self actionselector(annotationTapped forControlEvents:UIControlEventTouchUpInside];
   [self addSubview:calloutView];

   return self;

}

-(void)setSelectedBOOL)selected animatedBOOL)animated
{
 // show/hide callout and swap pin image
  calloutView.hidden = !selected;
  self.image = !selected ? normalPin : selectedPin;
  // dispatch an event to alert app a pin has been selected

  if(selected) [[NSNotificationCenter defaultCenter] postNotificationName"punchCardAnnotation" object:self];
}

-(void)annotationTappedid)sender{
   [self.delegate punchCardAnnotationClickedForDeal:self.punchDeal];
}



Best Answer-推荐答案


- (UIView*)hitTestCGPoint)point withEventUIEvent*)event
{
    UIView* hitView = [super hitTest:point withEvent:event];
    if ([hitView isKindOfClass:[UIButton class]]) {

    }
}

关于ios - 没有获得按钮操作/单击自定义 MKannotation 调用 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21986501/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4