0

私はActionSheetViewのようなサブビューを表示するアプリを作成しています.UIGridViewとUIPageControllをoutletから追加しましたが、セルをクリックしても応答しません.サブビューはnibファイルを持つViewControllerです.

ボタンを作成してポップアップビューにプログラムで追加すると、表示され、クリックイベントも取得されますが、アウトレット内の何も応答しません。

サブビューで userinteraction enable を設定しようとしましたが、うまくいきません。

バーボタンをクリックしてサブビューを表示する最初のビューのコードは次のとおりです。

- (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";
}

そして、これは私の画面がどのように見えるかです ここに画像の説明を入力

アップデート

今、私は自分の問題を理解しました。問題は、ビュー全体にタップリスナーを与えたことです。グリッドビューをサブビューとして追加しているので、セルを選択するのではなくセルをタップすると、ビュータップジェスチャが生成され、それがセルの理由です選択したことはありません、それは私が思うことです..

4

1 に答える 1

2

メイン ビューにすべてのサブビューを追加した後に、この行を追加します。

[self.view bringSubviewToFront:yourGridView];
于 2012-12-06T07:39:54.967 に答える