Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在UIVew下方的UIButton上启用用户交互?_Objective C_Ios_Uiview_Uibutton_User Interaction - Fatal编程技术网

Objective c 在UIVew下方的UIButton上启用用户交互?

Objective c 在UIVew下方的UIButton上启用用户交互?,objective-c,ios,uiview,uibutton,user-interaction,Objective C,Ios,Uiview,Uibutton,User Interaction,在我的程序中,我配置了一个ui视图,放置在许多ui按钮s上。这样,您就可以在视图中平移并移动按钮以及选择按钮本身。但是,当按钮位于该视图下方时,无法选择按钮。在这些条件下,有人知道如何配置UIButton的userInteractionEnabled吗?与其更改UIButton的userInteractionEnabled的值,不如将UIButton顶部UIView的userInteractionEnabled值设置为no 当UIView的userInteractionEnabled设置为YES

在我的程序中,我配置了一个
ui视图
,放置在许多
ui按钮
s上。这样,您就可以在视图中平移并移动按钮以及选择按钮本身。但是,当按钮位于该视图下方时,无法选择按钮。在这些条件下,有人知道如何配置
UIButton
userInteractionEnabled
吗?

与其更改UIButton的userInteractionEnabled的值,不如将UIButton顶部UIView的userInteractionEnabled值设置为no


当UIView的userInteractionEnabled设置为YES时,UIView正在“吞噬”事件。该按钮将永远不会接收任何事件。

这项技术对我来说很有效-警告:我只是输入了这个,它不是编译的,或者是作为起点给出的

  • 创建按钮并将其放置在视图层次结构的顶部(即它们正常交互并响应点击的位置,在UIView的顶部)
  • 创建按钮时,在数组中保留对按钮的引用

    NSMutableArray*arrayOfPeskyButtons

  • 保存按钮框的记录

    NSMutableArray* arrayOfPeskyFrames = [NSMutableArray mutableArray];
    for ((UIButton*)button in arrayOfPeskyButtons)
    {
        [arrayOfPeskyFrames addObject:[NSValue valueWithCGRect:button.frame];
    }
    
  • 当你的应用程序响应UIView上的一个操作时,或者如果你将其更改为UIScrollView(可能是最好的btw),那么相应地移动按钮的框架,以便它们在用户看来是固定的

  • 我使用这种技术创建了位于ScrollView顶部的按钮“叠加”,效果出奇地好。只需在scrollView委托方法中

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView
    
    记下scrollView偏移量,并根据scrollView的偏移量相应地调整按钮的每一帧

     CGPoint offset = scrollView.contentOffset;
    
    遍历按钮数组并移动它们

     int index = 0;
     for ((UIButton*)button in arrayOfPeskyButtons)
     {
         CGRect originalFrame = [[arrayOfPeskyFrames objectAtIndex:index]CGRectValue];
         CGRect currentFrame = button.frame;
         //adjust frame
         //e.g.
         currentFrame.origin.x = originalFrame.origin.x + offset.x;
    
         button.frame = currentFrame.;
         index++;
     }
    

    尝试在覆盖按钮的UI视图上禁用用户交互。我需要
    userInteractionEnabled
    将该视图设置为
    true
    ,以便我可以向其添加
    UIPangestureRecognitor
    。如果此视图是透明的,并且仅用于检测平移手势,那么为什么不将按钮放置在视图顶部呢?我只是我试过了。按钮阻止下方的
    ui视图
    识别平移事件。是的,它们是。我还没有尝试使用
    UIScrollView
    ,但我确信我能解决这个问题。谢谢你的帮助!我知道它正在这样做。也许我的问题不清楚。重要的是,
    UIView
    userInterActionEnabled
    设置为
    true
    ,以便它能够识别pan事件。