UIButton作为子视图没有响应

use*_*374 2 objective-c uibutton uiview ios

我有一个UIButton内部的UIView内部UIImageView没有响应触摸.我无法弄清楚为什么.我已经将代码分解为最简单的形式,同时仍然执行我的原始程序.

#import "TestVideoViewController.h"

@interface TestVideoViewController ()

@property (strong, nonatomic)UIImageView *panel;
@property (strong, nonatomic)UIView *panelSC;
@property (strong, nonatomic)UIButton *panelButtonSC;
@property (strong, nonatomic)UIButton *videoButton;

@end

@implementation TestVideoViewController

-(void) viewDidLoad {

    _panelButtonSC  = [UIButton buttonWithType:UIButtonTypeCustom];
    [_panelButtonSC addTarget:self action:@selector(buttonPressedSC:) forControlEvents:UIControlEventTouchUpInside];
    [_panelButtonSC setTitle:@"Open" forState:UIControlStateNormal];
    _panelButtonSC.frame = CGRectMake(511, 701, 66, 67);

    _panel = [[UIImageView alloc] initWithFrame:CGRectMake(100, 768, 824, 600)];
    _panel.backgroundColor = [UIColor whiteColor];

    _panelSC = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 784, 560)];
    _panelSC.backgroundColor = [UIColor whiteColor];

    _videoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_videoButton addTarget:self action:@selector(playVideo:) forControlEvents:UIControlEventTouchUpInside];
    [_videoButton setTitle:@"Play" forState:UIControlStateNormal];
    [_videoButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _videoButton.frame = CGRectMake(400, 400, 200, 40);

    [_panelSC addSubview:_videoButton];

    [_panel addSubview:_panelSC];

    [self.view addSubview:_panel];
    [self.view addSubview:_panelButtonSC];

}

- (IBAction)buttonPressedSC:(UIButton*)sender {

    [self animatePanelUp];
}

- (IBAction)playVideo:(UIButton*)sender {

    NSLog(@"play video");
}

- (void) animatePanelUp {
    [UIView animateWithDuration: 0.5
                          delay: 0.0
                        options: UIViewAnimationOptionCurveEaseIn
                     animations:^{
                         _panel.frame = CGRectMake(47, 166, 929, 602);
                     }
                     completion:nil];

}

@end
Run Code Online (Sandbox Code Playgroud)

我在这里看了每个类似的答案.据我所知,我所有的框架都是正确的.我必须要有一些简单而愚蠢的东西.为什么"playVideo"方法不会被解雇?它唯一有效的时间是我直接添加按钮self.view.

Gir*_*ari 8

默认情况下,UIImageView将userInteractionEnabled保持为false - 添加以下代码行.

_panel.userInteractionEnabled = true;
Run Code Online (Sandbox Code Playgroud)