0

ビューが表示されるときに親ビューの上に表示されるサブビューに 2 つのボタンを追加したいと考えています。ボタンは正しく初期化されて表示されますが、押しても反応しません。理由を知っている人はいますか?これが私のコードです:

-(void) viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
    self.view.backgroundColor = [UIColor blackColor];
    //Animation View
    imageView= [[UIImageView alloc] initWithFrame:CGRectMake(0, 499, 320, 0)];
    imageView.image = [UIImage imageNamed:@"trans.png"];
    [imageView setClipsToBounds:YES];
    [imageView setContentMode:UIViewContentModeBottom];
    [self.view addSubview:imageView];


    [UIView animateWithDuration:1.0f
                          delay:0.5f
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^(void) {
                         imageView.frame = CGRectMake(0, 92, 320, 320);

                     }
                     completion:NULL];
    [self.view bringSubviewToFront:imageView];
    // Animation View Buttons
    //1 Amazon
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *button=[UIImage imageNamed:@"button.png"];
    [button1 setImage:button forState:UIControlStateNormal];
    button1.frame = CGRectMake(0, 290, 80, 30);
    button1.backgroundColor=[UIColor whiteColor];
    button1.showsTouchWhenHighlighted=YES;

    [button1 addTarget:self
                action:@selector(openAmazon:)
     forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:button1];

    //2 iTunes
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button2 setImage:button forState:UIControlStateNormal];
    button2.frame = CGRectMake(82, 290, 80, 30);
    button2.backgroundColor=[UIColor whiteColor];
    button2.showsTouchWhenHighlighted=YES;

    [button2 addTarget:self
     action:@selector(openiTunes:)
     forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:button2];



}
4

3 に答える 3

5

オプション UIViewAnimationOptionAllowUserInteraction を使用する必要があります

...
options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction
...
于 2012-12-05T11:18:12.133 に答える
1

userInteractionEnabledimageView でプロパティを設定していることを確認してください。

[imageView setUserInteractionEnabled:YES];
于 2012-12-05T11:04:14.777 に答える
1
[self.view bringSubviewToFront:imageView];

フレームを増やした後、画像ビューを前面に移動しています。これにより、ボタンのアクションがブロックされています

于 2012-12-05T11:12:27.617 に答える