iOS 地图上长按无效
iOS Long Press is not working on Map
我试图在长按以在该位置周围绘制覆盖图后获取该位置。但是我设置的长按动作并没有触发
-(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];
}
太棒了,所以你的 mapview 对象是 nil。
如果您使用的是界面生成器,那么您还没有将 属性 附加到可视组件。这是基本的东西,有很多关于如何做这种事情的教程。
简而言之,您应该已经拥有类似的内容:
@property (nonatomic, weak) IBOutlet MKMapView *mapview;
这没有连接到界面生成器组件,那是你的问题!
编码愉快...
我试图在长按以在该位置周围绘制覆盖图后获取该位置。但是我设置的长按动作并没有触发
-(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];
}
太棒了,所以你的 mapview 对象是 nil。
如果您使用的是界面生成器,那么您还没有将 属性 附加到可视组件。这是基本的东西,有很多关于如何做这种事情的教程。
简而言之,您应该已经拥有类似的内容:
@property (nonatomic, weak) IBOutlet MKMapView *mapview;
这没有连接到界面生成器组件,那是你的问题!
编码愉快...