UISwitch无法在iOS版Google Maps SDK上使用吗? [英] UISwitch doesn't work on Google Maps SDK for iOS?

查看:65
本文介绍了UISwitch无法在iOS版Google Maps SDK上使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的iOS应用创建一个放置在Google Maps的mapView_上的UISwitch,但似乎不起作用.

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

详细来说,我首先按照Google的指示进行操作,创建了mapView_,然后将其设为我的viewcontroller视图:

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

self.view = mapView_;

然后,我以编程方式创建了一个UISwitch并将其添加为子视图:

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

但是当我同时触摸模拟器和设备中的开关时,它并没有从ON-> OFF或OFF-> ON更改其状态.我什至尝试了其他UIControlEvent,例如UIControlEventValueChanged,但没有用.为了确保代码能正常工作,我尝试使用普通测试viewcontroller的普通视图(这意味着,不使用google maps),效果很好!

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?

感谢堆!

推荐答案

您可以通过将UISwitch和GMSMapView都添加到单个UIView父级来解决此问题,而不是将UISwitch添加为GMSMapView的子级.是的,这意味着您需要同时放置GMSMapView和UISwitch.

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.

这篇关于UISwitch无法在iOS版Google Maps SDK上使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆