我的子视图没有响应点击事件

时间:2012-12-06 07:36:55

标签: iphone ios gridview touch

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

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

我试图在我的子视图中设置userinteraction enable但它没有做任何好处。

这是我的第一个视图的代码,它通过单击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";
}

这就是我的屏幕的样子 enter image description here

更新

现在我想出了我的问题,问题是我给了我的整个视图一个点击列表器,现在我添加网格视图作为子视图所以当我点击单元格而不是然后选择单元格它将生成视图点击手势和这就是为什么细胞从未被选中,这就是我的想法..

1 个答案:

答案 0 :(得分:2)

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

[self.view bringSubviewToFront:yourGridView];