在MKMapView上添加UIView [英] Adding an UIView over a MKMapView

查看:83
本文介绍了在MKMapView上添加UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的MKMapView的角落放置一个按钮,以控制地图是否保持锁定在用户的位置.我要记住的是创建一个带有按钮的UIView,并将其添加到我的MKMapView上(而不是作为注释或其他内容),我无法使用Interface Builder来解决这个问题.

I am trying to put a button in the corner of my MKMapView to control whether the map stays locked on to the user's location. What I have in mind is to create a UIView with a button on and add it over my MKMapView (not as an annotation or something) I can't figure this out with Interface Builder.

如何以编程方式添加此按钮?

How can I add this button programmatically?

控制它是否实际上跟随用户等的内容已经排序-只需按钮即可.

推荐答案

看起来您正在直接将控制器的view出口设置为MKMapView对象,而不是包含MKMapView对象的UIView对象.在这种情况下,您不能将按钮放在IBMKMapView对象的顶部.有两种处理方法,

It looks like you are directly setting the controller's view outlet to an MKMapView object rather than a UIView object containing the MKMapView object. You cannot drop the button in such case on top of the MKMapView object in the IB. There are two ways you can deal with this,

  1. 声明按钮的插座,然后将按钮放在IB中.不必在MKMapView对象的顶部.将出口设置为例如button属性.然后在viewDidLoad中设置buttonframe后执行[self.view addSubview:self.button];. (或)
  2. 将新的UIView对象拖放到IB中,然后将MKMapView对象放入其中.将控制器的view设置为此容器UIView对象.稍后将按钮放在MKMapView对象顶部,并将其设置在适当的位置.
  1. Declare an outlet for the button and drop the button in the IB. This needn't be on top of the MKMapView object. Set the outlet to, say, a button property. Then in viewDidLoad do [self.view addSubview:self.button]; after setting the button's frame. (or)
  2. Drop a new UIView object in IB and put the MKMapView object inside it. Set the controller's view to this container UIView object. Later drop the button on top of the MKMapView object and set it to its appropriate location.

这篇关于在MKMapView上添加UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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