在MKMapView上添加UIView [英] Adding an UIView over a MKMapView
问题描述
我试图在我的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
对象.在这种情况下,您不能将按钮放在IB
中MKMapView
对象的顶部.有两种处理方法,
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,
- 声明按钮的插座,然后将按钮放在
IB
中.不必在MKMapView
对象的顶部.将出口设置为例如button
属性.然后在viewDidLoad
中设置button
的frame
后执行[self.view addSubview:self.button];
. (或) - 将新的
UIView
对象拖放到IB中,然后将MKMapView
对象放入其中.将控制器的view
设置为此容器UIView
对象.稍后将按钮放在MKMapView
对象顶部,并将其设置在适当的位置.
- Declare an outlet for the button and drop the button in the
IB
. This needn't be on top of theMKMapView
object. Set the outlet to, say, abutton
property. Then inviewDidLoad
do[self.view addSubview:self.button];
after setting thebutton
'sframe
. (or) - Drop a new
UIView
object in IB and put theMKMapView
object inside it. Set the controller'sview
to this containerUIView
object. Later drop the button on top of theMKMapView
object and set it to its appropriate location.
这篇关于在MKMapView上添加UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!