0

我试图在长按后获得该位置以在该位置周围放置一个覆盖层。但是,我在长按上设置的动作没有触发。

-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];

//add the long press options

//single finger long press
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(getMapCoordinateFromTouch:)];
[longPressGesture setNumberOfTouchesRequired:1];
longPressGesture.delegate = self;
[self.mapview addGestureRecognizer:longPressGesture];

//double finger long press
UILongPressGestureRecognizer *doubleLongPressGesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(removeBoundry:)];
[doubleLongPressGesture setNumberOfTouchesRequired:2];
doubleLongPressGesture.delegate = self;
[self.mapview addGestureRecognizer:doubleLongPressGesture];

这是它调用的函数

-(void)getMapCoordinateFromTouch:(UILongPressGestureRecognizer *) gesture{
if(gesture.state == UIGestureRecognizerStateBegan){
    CGPoint touchlocation = [gesture locationInView:self.mapview];
    pressedloc = [self.mapview convertPoint:touchlocation toCoordinateFromView:self.mapview];
    [self createBundarywithRadius:.1];    
}
4

1 回答 1

1

酷,所以你的地图视图对象是零。

如果您使用的是界面生成器,那么您还没有将您的属性附加到可视化组件。这是基本的东西,有很多关于如何做这种事情的教程。

简而言之,你应该已经有了类似的东西:

@property (nonatomic, weak) IBOutlet MKMapView *mapview;

这与界面构建器组件无关,那是您的问题!

快乐的编码...

于 2016-06-14T15:12:44.373 回答