iOS Long Press无法在Map上运行

时间:2016-06-14 14:00:45

标签: ios objective-c uilongpressgesturerecogni

我试图在长按后获取该位置以围绕该位置覆盖覆盖物。但是,我在长按时设定的动作并未触发。

-(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];    
}

1 个答案:

答案 0 :(得分:1)

很酷,所以你的mapview对象是零。

如果您使用的是界面构建器,则表示您尚未将属性附加到可视组件。这是基本的东西,有很多关于如何做这种事情的教程。

简而言之,您应该已经拥有类似的内容:

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

这不是连接到界面构建器组件,这是你的问题!

快乐的编码......