Iphone UIButton在';它位于地图视图的顶部

Iphone UIButton在';它位于地图视图的顶部,iphone,ios,uibutton,mkmapview,clickable,Iphone,Ios,Uibutton,Mkmapview,Clickable,我找了很多时间,但到目前为止,我没有找到确切的问题 我在InterfaceBuilder中创建了一个地图视图。通过点击一个按钮,我添加了另一个视图 self.buttonView = [[ButtonView alloc] init]; self.buttonView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:self.buttonView]; 在created buttonView中,我以编程方式创建了5个按钮

我找了很多时间,但到目前为止,我没有找到确切的问题

我在InterfaceBuilder中创建了一个地图视图。通过点击一个按钮,我添加了另一个视图

self.buttonView = [[ButtonView alloc] init];
self.buttonView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.buttonView];
在created buttonView中,我以编程方式创建了5个按钮,如下所示:

UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button1.frame = CGRectMake(25, 275, 100, 30);
[button1 setTitle:@"button1!" forState:UIControlStateNormal];
[self addSubview:button1];
按钮显示正确,但不可单击。我试过好几种方法,但到目前为止似乎都不管用。 每当我点击一个按钮,地图视图就会被点击。例如,当我双击按钮时,地图视图将放大。mapView和buttonView都是“视图”的子视图

我希望buttonView位于地图视图的顶部(确实如此),地图视图在buttonView的下方滚动(确实如此),而按钮保持在原来的位置(确实如此),但不可单击

非常感谢您的帮助!:-)


EDIT1:threaded
self.buttonView.userInteractionEnabled=YES-不会更改任何内容。(也适用于按钮本身!

不确定这是打字错误:您应该将子视图添加到self.buttonView,对吗

[self.buttonView addSubview:button1]

查看它的帮助信息

不确定这是打字错误:您应该将子视图添加到self.buttonView,对吗

[self.buttonView addSubview:button1]

请看它的帮助

我曾经遇到过类似的情况,解决方案是

[button1 setExclusiveTouch:YES];

如果控件元素下的视图也处理触摸事件,则控件可能以意外的方式工作。

我曾经遇到过类似的情况,解决方案是

[button1 setExclusiveTouch:YES];

如果控件元素下的视图也处理触摸事件,则控件可能会以意外方式工作。

非常简单的错误,我的“上部”视图不可见,并且拒绝单击下面的按钮:S

非常简单的错误,我的“上部”视图不可见并拒绝单击下面的按钮:S

我使用了interface builder,但没有看到按钮。我必须将MKMapView设置为隐藏,直到按钮显示并处于正确位置。然后我将MKMapView设置为可见

以下是我必须在界面生成器中执行的步骤,以使我的按钮显示出来

  • 创建包含视图的UIViewController
  • 添加MKMapView并设置约束
  • 在与MKMapView相同的视图中添加UIButton,设置图像和文本,只要适用。如果在尝试调整或移动按钮时MKMapView消失,则地图视图已将其宽度和高度设置为零。在地图视图的大小检查器中输入新值,它将重新调整大小。或者,您可以将按钮移到地图的其他位置MKMapView,然后将按钮移回所需位置

  • 重要的部分是为UIButton设置约束。我将MKMapView设置为隐藏,直到获得正确的大小和位置,然后将其设置为可见

  • 下面是它在模拟器中的外观


    我使用了interface builder,但没有看到按钮。我必须将MKMapView设置为隐藏,直到按钮显示在正确的位置。然后我将MKMapView设置为可见

    以下是我必须在界面生成器中执行的步骤,以使我的按钮显示出来

  • 创建包含视图的UIViewController
  • 添加MKMapView并设置约束
  • 在与MKMapView相同的视图中添加UIButton,设置图像和文本,只要适用。如果在尝试调整或移动按钮时MKMapView消失,则地图视图已将其宽度和高度设置为零。在地图视图的大小检查器中输入新值,它将重新调整大小。或者,您可以将按钮移到地图的其他位置MKMapView,然后将按钮移回所需位置

  • 重要的部分是为UIButton设置约束。我将MKMapView设置为隐藏,直到获得正确的大小和位置,然后将其设置为可见

  • 下面是它在模拟器中的外观


    使用Cartogaphy,我还必须设置类似于@Maria的高度和宽度限制。因此,以下操作不起作用:

    categoryButton.addTarget(self, action: "toggleCategoryDropdown:", forControlEvents: UIControlEvents.TouchUpInside)
    categoryButton.backgroundColor = UIColor.purpleColor()
    categoryButton.userInteractionEnabled = true
    
    self.addSubview(categoryButton)
    
    constrain(categoryButton) {
        categoryButton in
    
        categoryButton.top == categoryButton.superview!.top + 26
        categoryButton.left == categoryButton.superview!.left + globalConfig.margin
    }
    
    但这确实奏效了

    categoryButton.addTarget(self, action: "toggleCategoryDropdown:", forControlEvents: UIControlEvents.TouchUpInside)
    categoryButton.backgroundColor = UIColor.purpleColor()
    categoryButton.userInteractionEnabled = true
    
    self.addSubview(categoryButton)
    
    constrain(categoryButton) {
        categoryButton in
    
        categoryButton.top == categoryButton.superview!.top + 26
        categoryButton.left == categoryButton.superview!.left + globalConfig.margin
        categoryButton.width == 100
        categoryButton.height == 100
    }
    

    使用Cartogaphy,我还必须设置类似于@Maria的高度和宽度限制。因此以下操作不起作用:

    categoryButton.addTarget(self, action: "toggleCategoryDropdown:", forControlEvents: UIControlEvents.TouchUpInside)
    categoryButton.backgroundColor = UIColor.purpleColor()
    categoryButton.userInteractionEnabled = true
    
    self.addSubview(categoryButton)
    
    constrain(categoryButton) {
        categoryButton in
    
        categoryButton.top == categoryButton.superview!.top + 26
        categoryButton.left == categoryButton.superview!.left + globalConfig.margin
    }
    
    但这确实奏效了

    categoryButton.addTarget(self, action: "toggleCategoryDropdown:", forControlEvents: UIControlEvents.TouchUpInside)
    categoryButton.backgroundColor = UIColor.purpleColor()
    categoryButton.userInteractionEnabled = true
    
    self.addSubview(categoryButton)
    
    constrain(categoryButton) {
        categoryButton in
    
        categoryButton.top == categoryButton.superview!.top + 26
        categoryButton.left == categoryButton.superview!.left + globalConfig.margin
        categoryButton.width == 100
        categoryButton.height == 100
    }
    

    你能澄清一下你要将
    按钮视图添加到哪个视图中吗?你想让这个视图浮动在地图视图的顶部吗?还是想让这个视图与地图一起滚动?我正在将五个UIButton添加到ButtonView,它是标准视图的一个子视图。我想要ButtonView(带五个按钮)保持在地图视图的顶部,这意味着只有地图视图应该滚动(“在”按钮视图下),按钮应该保持不变。如果只添加
    UIButtonView
    而不是
    ButtonView
    ,您会遇到同样的问题吗?不…但是如果我将它们添加到另一个视图中,应该是可能的?!我的意思是说
    UIButtonView
    …修复了这个问题…您能澄清一下您将
    ButtonView
    添加到哪个视图吗?您想吗将此视图浮动在地图视图的顶部?还是希望此视图与地图一起滚动?我正在将五个UIButtons添加到buttonView,这是标准视图的子视图。我希望buttonView(带有五个按钮)保持在地图视图的顶部,这意味着只有地图视图应该滚动(“buttonView”下),按钮应该保持不变如果你只添加一个
    UIButtonView
    而不是
    ButtonView
    ,你会遇到同样的问题吗?不…但如果我将它们添加到另一个视图中,应该是可能的?!我的意思是说
    UIButtonView
    …修复了…这不是问题,它是正确的,否则你不会看到按钮。代码在buttonView的init方法中,所以只有self,而不是self。buttonView这不是问题,它是正确的,否则你将看不到按钮。代码在buttonView的init方法中,所以只有self,而不是self。buttonView哇,谢谢!这是一个具有MapView隐藏属性的技巧,它确实能满足我的需要。哦,谢谢!这是一个多么好的技巧用MapVie