iOS 长按不适用于 map

标签 ios objective-c uilongpressgesturerecogni

我试图在长按以在该位置周围绘制覆盖图后获取该位置。但是,我设置的长按 Action 并没有触发。

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

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

快乐编码...

关于iOS 长按不适用于 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37814216/

相关文章:

ios - 将 Objective-C 无参数 init 重写为 Swift convenience init

ios - 如何提高 Quickblox 聊天应用程序的视频质量?

ios - UITableView 上未调用长按手势

ios - 为什么核心数据中的文件仍然存在,尽管我可以在核心数据中成功删除对象

iphone - iOS:如何使UIImage模糊?

objective-c - SBTableAlert 崩溃

ios - 如何在 HMSegmentedControl 上重复或重新选择选定的段?

ios - 将功能绑定(bind)到键盘中的 "Search"按钮

ios - 2 个同步的 UILongPressGestureRecognizer

ios - 当有长按手势识别器时,UIButton 不会改变文本颜色