iSu*_*esh 2 objective-c ios ios6 ios7
我在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);
}
}
Run Code Online (Sandbox Code Playgroud)
这里的主要问题是我长按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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3238 次 |
| 最近记录: |