【问题标题】:My subview is not responding click event我的子视图没有响应点击事件
【发布时间】:2012-12-06 07:36:54
【问题描述】:

我正在创建一个显示像 ActionSheetView 这样的子视图的应用程序,并且我已经通过插座添加了 UIGridView 和 UIPageControll,但是现在当我单击单元格时它没有响应,我的子视图是一个带有 nib 文件的 ViewController。

如果我创建一个按钮并以编程方式添加到我的弹出视图中,那么它将显示,并且还会获得点击事件,但插座中的任何内容都没有响应。

我试图在我的子视图中设置用户交互启用,但它没有任何好处。

这是我的第一个视图代码,通过单击 barbutton 显示子视图:

- (void)popUpView:(id)sender {
    //self.view.backgroundColor = [UIColor darkGrayColor];

   bGView = [[UIView alloc] init];   /this is the background view and all view is added in it
    bGView.frame = CGRectMake(0,0,320,490);
    bGView.backgroundColor = [UIColor clearColor];
    bGView.alpha = 0.8 ;

    CGRect  viewFrame = CGRectMake(10, 90, 300, 300);
    aPopUpViewController = [[PopUpViewController alloc] initWithNibName:@"PopUpViewController" bundle:nil];        //this is my view controller and when this shows on screen it display my greed view

    aPopUpViewController.view.frame = viewFrame; 
    aPopUpViewController.view.userInteractionEnabled = YES;

    [bGView addSubview:aPopUpViewController.view];

    button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self 
               action:@selector(aMethod:)
     forControlEvents:UIControlEventTouchDown];
    button.backgroundColor = [UIColor clearColor];
    [button setBackgroundImage:[UIImage imageNamed:@"close_button.png"] forState:UIControlStateNormal];
    button.frame = CGRectMake(-1, 80, 30, 30);
    [bGView addSubview:button];

    //for view animation

    /*
    // from bottom to center animation

    [bGView setFrame:CGRectMake( 0.0f, 480.0f, 320.0f, 480.0f)]; //notice this is OFF screen!
    [UIView beginAnimations:@"animateTableView" context:nil];
    [UIView setAnimationDuration:0.4];
    [bGView setFrame:CGRectMake( 0.0f, 0.0f, 320.0f, 480.0f)]; //notice this is ON screen!
    [UIView commitAnimations];*/

    //for page like effect

    /*[UIView transitionWithView:self.view duration:0.5
                       options:UIViewAnimationOptionTransitionCurlUp //change to whatever animation you like
                    animations:^ { [self.view addSubview:bGView]; }
                    completion:nil];*/

    /*CATransition *transition = [CATransition animation];
     transition.duration = 1.0;
     transition.type = kCATransitionReveal; //choose your animation
     [bGView.layer addAnimation:transition forKey:nil];
     [self.view addSubview:bGView];*/

    aPopUpViewController.view.userInteractionEnabled = YES;
    bGView.userInteractionEnabled = YES;
    self.view.userInteractionEnabled = YES;

    bGView.transform = CGAffineTransformMakeScale(0.01, 0.01);
    [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        bGView.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished){
        // do something once the animation finishes, put it here
    }];

     [self.view addSubview:bGView];


    addLabel.enabled = NO;
    clipArt.enabled = NO;
    emailItem.enabled = NO;
    closeButton.enabled = NO;
    self.navigationController.topViewController.title = @"Choose ClipArt";

    ExampleAppDataObject* theDataObject = [self theAppDataObject];

   theDataObject.navBarHide = @"no";

}

- (void)aMethod:(id)sender
{
    //[aPopUpViewController.view removeFromSuperview];
    //[button removeFromSuperview];

    /*[UIView transitionWithView:self.view duration:0.5
                       options:UIViewAnimationOptionTransitionCrossDissolve//change to whatever animation you like
                    animations:^ { [bGView removeFromSuperview]; }
                    completion:nil];*/

    [bGView removeFromSuperview];

    addLabel.enabled = YES;
    clipArt.enabled = YES;
    emailItem.enabled = YES;
    closeButton.enabled = YES;

    self.navigationController.topViewController.title = @"Greeting's";

    ExampleAppDataObject* theDataObject = [self theAppDataObject];

    theDataObject.navBarHide = @"yes";
}

这就是我的屏幕的样子

更新

现在我发现了我的问题,问题是我给了我的整个视图一个点击列表,现在我将网格视图添加为子视图,所以当我点击单元格而不是选择单元格时,它会生成视图点击手势和这就是为什么从未选择单元格的原因,这就是我的想法..

【问题讨论】:

    标签: iphone ios gridview touch


    【解决方案1】:

    在主视图中添加每个子视图后添加此行..

    [self.view bringSubviewToFront:yourGridView];
    

    【讨论】:

    • 但我的 gridview 不是子视图,它被添加到我的第二个视图控制器中,比如 MMGridView。还有这个工作吗?
    • 任何你添加gridview的地方只要写这个代码老兄......就像[yourView bringSubviewToFront:yourGridView];
    • 它让我的grideview在前面但仍然触摸不显示。
    • 你把它从网点交给代表??
    • 能不能把手势去掉再试试??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多