【问题标题】:How can I disable the multiple user interactions on a screen at a same point of time如何在同一时间点禁用屏幕上的多个用户交互
【发布时间】:2015-02-23 12:49:59
【问题描述】:

在我的应用程序中包含 no.of UIElements,例如 facebook button, twitter button, logout button, imageview with gestures

`

facebookBtn = [UIButton buttonWithType:UIButtonTypeCustom];
 [facebookBtn setImage:@"facebook.png"];
 [facebookBtn addTarget:self action:@selector(switchToFacebookShare) forControlEvents:UIControlEventTouchUpInside];
 [facebookBtn setFrame:CGRectMake(0, 50, 24, 24)];
[self.view addsubview:facebookBtn];`

 `twitterBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  [twitterBtn setImage:@"facebook.png"];
  [twitterBtn addTarget:self action:@selector(switchToTwitterShare) forControlEvents:UIControlEventTouchUpInside];
  [twitterBtn setFrame:CGRectMake(0, 100, 24, 24)];
  [self.view addsubview:twitterBtn];`


`imageTapGesture =  [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sectionTapping:)];
 [imageTapGesture setNumberOfTapsRequired:1];`

`sectionPortraitImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
 [sectionPortraitImageView setUserInteractionEnabled:YES];
 [sectionPortraitImageView addGestureRecognizer:imageTapGesture];
 [contentView addSubview:sectionLandscapeImageView];`

像这样我添加了所有元素 当用户一次单击所有按钮时,所有三个功能都在工作。 这里只需要进行一项操作。

我该如何解决这个问题?

【问题讨论】:

  • 在您的应用中,您在按钮中添加手势?
  • 不,我只为图像视图添加了点击手势。当应用程序第一次启动时,然后如果我点击所有元素,所有元素都在执行
  • 然后在此处添加您的一些代码。
  • 在这里,我只能以编程方式添加按钮创建..
  • UIButtonexclusiveTouch属性设置为YES

标签: ios user-interface uiimageview uibutton


【解决方案1】:

一次处理多个触摸问题并设置单个属性

[sectionLandscapeImageView setExclusiveTouch:YES]; // 处理所有子视图的多点触摸用户交互

 -(void)multipleTouchHandling
{
    self.view.multipleTouchEnabled=NO;
    self.view.exclusiveTouch=YES;
    for(UIView* view1 in self.view.subviews)
    {
        if([view1 isKindOfClass:[UIButton class]])
        {
            UIButton* btnVw = (UIButton*)view1;
            [btnVw setExclusiveTouch:YES];
        }
    }
}

【讨论】:

    【解决方案2】:

    我看到了一些摆脱这种情况的方法。

    1. 你保持每个按钮的强链接,并制作

      [someButton setUserInteractionEnabled:NO]
      

    对于用户点击某人后的每个元素。但这需要大量的时间和代码

    1. (我认为更好的解决方案)或者您可以在视图顶部显示UIActivityIndicatorView,以在您处理某些数据或进行其他操作时阻止所有用户交互。

    【讨论】:

    • 感谢您的回复,我没有从执行正常按钮单击事件的服务器获取任何数据
    • 那么,这解决了问题还是需要其他解决方案?
    • 如果我也使用UIActivityIndicatorView,它会执行用户点击的所有操作。不会这样显示吧?
    • UIActivityIndi​​catorView 只是 UIView 的子视图,如果您在视图上添加 activityindicator 作为子视图,则可以拦截所有界面操作。如果我理解正确,您的算法是下一个:1)用户单击某个按钮 2)您在控制器视图上添加 UIActivityIndi​​catorView 3)您开始您的操作 4)您处理您的操作结束并从控制器视图中删除 UIActivityIndi​​catorView。
    猜你喜欢
    • 2011-12-14
    • 1970-01-01
    • 2019-06-17
    • 2016-07-11
    • 1970-01-01
    • 2013-03-03
    • 2012-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多