UISwitch doesn't work on Google Maps SDK for iOS?

南笙酒味 提交于 2021-02-07 19:49:43

问题


I'm trying to create a UISwitch laid on mapView_ of Google Maps for my iOS app, but it seems not to work.

In details, I first followed instruction from google, created mapView_, then made it my viewcontroller's view:

self.view = mapView_;

Then, I created an UISwitch programmatically and added it as a subview:

mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(50, 360, 0, 0)];
[mySwitch setBackgroundColor:[UIColor clearColor]];
[mySwitch addTarget:self
             action:@selector(changeSwitch:)
        forControlEvents:UIControlEventTouchDown];
[mapView_ addSubview:mySwitch];

But when I touched the switch both in simulator and device, it didn't change its state from ON->OFF or OFF->ON. I even tried different UIControlEvent, such as UIControlEventValueChanged but it didn't work. To make sure that the code should work, I tried on a normal view of a normal test viewcontroller (that means, not using google maps), it worked fine!

Does anyone have any comment about this issue?

Thanks heaps!


回答1:


You can work around this issue by adding both the UISwitch and the GMSMapView to a single UIView parent, instead of adding the UISwitch as a child of a GMSMapView. Yes, this means you need to position both the GMSMapView and the UISwitch.



来源:https://stackoverflow.com/questions/18827835/uiswitch-doesnt-work-on-google-maps-sdk-for-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!