![](/img/trans.png)
[英]iOS - Long Press Gesture Recognizer for UIButton in UITableViewCell
[英]Adding Long Press Gesture Recognizer to Google Map in iOS
我在UIScrollView中添加了GMSMapView,并且还将表视图添加到了UIScrollView。 没有我的任务是如果长按在地图上的任何位置我将获得该地址并将该地址添加到表视图,并且我还想在该位置添加标记。
我编写了下面的代码,用于将长按手势识别器添加到地图中,但它无法正常工作。
- (void)viewDidLoad
{
[super viewDidLoad];
self->map.delegate = self;
CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
UIScrollView *scroll=[[UIScrollView alloc] initWithFrame:fullScreenRect];
[self.view addSubview:scroll];
scroll.contentSize=CGSizeMake(320,1000);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:21.0000 longitude:78.0000 zoom:4.5];
map = [GMSMapView mapWithFrame:CGRectMake(0,0, self.view.frame.size.width,390) camera:camera];
[scroll addSubview:map];
UITableView *tab = [[UITableView alloc]initWithFrame:CGRectMake(0, 410, self.view.bounds.size.width, 300) style:UITableViewStylePlain];
[scroll addSubview:tab];
tab.delegate = self;
tab.dataSource = self;
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(mapLongPress:)];
longPressGesture.minimumPressDuration = 1.5;
[map addGestureRecognizer:longPressGesture];
}
-(void)mapLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
if(gestureRecognizer.state == UIGestureRecognizerStateBegan)
{
NSLog(@"%f",coordinate.latitude);
NSLog(@"%f",coordinate.longitude);
}
}
这里的主要问题是我长按MapView后没有调用“mapLongPress”方法。
任何人都可以帮助我。
您可以使用默认的MapVIew LongPress事件
/**
* Called after a long-press gesture at a particular coordinate.
*
* @param mapView The map view that was pressed.
* @param coordinate The location that was pressed.
*/
- (void)mapView:(GMSMapView *)mapView
didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.