具有google地图视图的IOS应用程序未触发touchesEnded:withEvent:method
我正在开发一个IOS应用程序,它使用谷歌地图SDK在其中渲染地图。我实际上有一个视图控制器,它包含另一个视图控制器,实际上是处理地图渲染的控制器。我想要实现的是在用户移动地图相机并结束触摸它之后执行一些操作。我发现,对于这种特殊情况,最好的选择是重写touchesend:withEvent:method。我在包含的视图控制器中重写此方法,但由于某些原因,它没有被触发。我的问题应该是什么原因 顺便说一句,mapView:idleAtCameraPosition:不符合我的要求,因为我需要在用户释放触摸屏(停止移动地图)时执行操作 下面是一些代码。它与google maps SDK for IOS提供的示例基本相同 接口具有google地图视图的IOS应用程序未触发touchesEnded:withEvent:method,ios,objective-c,google-maps,events,Ios,Objective C,Google Maps,Events,我正在开发一个IOS应用程序,它使用谷歌地图SDK在其中渲染地图。我实际上有一个视图控制器,它包含另一个视图控制器,实际上是处理地图渲染的控制器。我想要实现的是在用户移动地图相机并结束触摸它之后执行一些操作。我发现,对于这种特殊情况,最好的选择是重写touchesend:withEvent:method。我在包含的视图控制器中重写此方法,但由于某些原因,它没有被触发。我的问题应该是什么原因 顺便说一句,mapView:idleAtCameraPosition:不符合我的要求,因为我需要在用户释放
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <GoogleMaps/GoogleMaps.h>
@interface MTMapViewController : UIViewController <CLLocationManagerDelegate, GMSMapViewDelegate>
@property (nonatomic, strong) CLLocationManager *manager;
@end
#导入
#进口
#进口
@接口MTMapViewController:UIViewController
@属性(非原子,强)CLLocationManager*manager;
@结束
实施
#import "MTMapViewController.h"
#import <GoogleMaps/Googlemaps.h>
#import <CoreLocation/CoreLocation.h>
@implementation MTMapViewController {
GMSMapView *mapView_;
GMSMarker *marker;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)loadView {
[super loadView];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:nil];
mapView_.delegate = self;
mapView_.myLocationEnabled = YES;
mapView_.mapType = kGMSTypeNormal;
mapView_.settings.myLocationButton = YES;
mapView_.settings.compassButton = YES;
self.view = mapView_;
self.manager = [[CLLocationManager alloc] init];
self.manager.delegate = self;
[self.manager startUpdatingLocation];
marker = [[GMSMarker alloc] init];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
[manager stopUpdatingLocation];
CLLocation *currentLocation = [self.manager location];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithTarget:currentLocation.coordinate
zoom:17];
mapView_.camera = camera;
marker.position = currentLocation.coordinate;
marker.icon = [UIImage imageNamed:@"passenger_marker.png"];
marker.map = mapView_;
}
- (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position {
marker.position = position.target;
}
- (void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position {
NSLog(@"mapView:idleAtCameraPosition fired");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
//This wont be invoked
NSLog(@"touchesEnded:withEvent: fired");
}
@end
#导入“MTMapViewController.h”
#进口
#进口
@MTMapViewController的实现{
GMSMapView*地图视图;
GMSMarker*标记;
}
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(void)负荷视图{
[超级加载视图];
地图视图=[GMSMapView-mapWithFrame:CGRectZero相机:无];
mapView_.delegate=self;
mapView_u2;.myLocationEnabled=是;
mapView_u2;.mapType=kGMSTypeNormal;
mapView_979;.settings.myLocationButton=是;
mapView.settings.compassButton=是;
self.view=mapView;
self.manager=[[CLLocationManager alloc]init];
self.manager.delegate=self;
[self.manager startUpdatingLocation];
标记=[[GMSMarker alloc]init];
}
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后执行任何其他设置。
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(无效)位置管理器:(CLLocationManager*)管理器更新位置:(NSArray*)位置{
[管理器停止更新位置];
CLLocation*currentLocation=[self.manager位置];
GMSCameraPosition*摄像头=[GMSCameraPosition cameraWithTarget:currentLocation.coordinate
变焦:17];
mapView_.camera=摄影机;
marker.position=currentLocation.坐标;
marker.icon=[UIImage ImageName:@“passenger_marker.png”];
marker.map=mapView;
}
-(无效)地图视图:(GMSMapView*)地图视图未更改相机位置:(GMSCameraPosition*)位置{
marker.position=position.target;
}
-(无效)地图视图:(GMSMapView*)地图视图idleAtCameraPosition:(GMSCameraPosition*)位置{
NSLog(@“映射视图:已激发idleAtCameraPosition”);
}
-(void)touchesend:(NSSet*)toucheevent:(UIEvent*)event{
//这不会被调用
NSLog(@“touchesend:withEvent:fired”);
}
@结束
感谢您的帮助当心idleAtCameraPosition是当地图停止移动时,而不是当您抬起手指时 我必须将GSMapView子类化,并添加PangestureRecognitor>>当手指抬起时,状态结束
为什么在ViewController中有ViewController?您是否在地图视图上设置了代理?显示一些代码怎么样?=)Hello@Brett,我已经按照您的要求添加了一些代码,我使用了这种方法,因为我看到在整个屏幕的特定区域内渲染地图是最简单的方法,而无需更改google maps SDK for IOS提供的示例的任何代码(它们在UIViewController自定义类中渲染地图)你的代码中有些东西没有意义。例如,您将该类设置为mapView的委托,但该类未实现GMSMapViewDelegate。这可能就是为什么你看不到委托调用,我不是一个足够的obj-c程序员。您至少应该在那一行看到警告。@Brett这是my.m文件(实现),GMSMapViewDelegate协议采用在my.h文件(接口)中声明。GMSMapViewDelegate方法工作得很好,因此您的论点是错误的。在这种情况下,我不理解您所说的“我在包含的视图控制器中重写此方法,但由于某种原因它没有被触发”是什么意思