gpt4 book ai didi

ios - UIButton 作为 subview 没有响应

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:55:44 25 4
gpt4 key购买 nike

我在 UIImageView 内的 UIView 内有一个 UIButton,它不响应触摸。我不知道为什么。我已将代码分解为最简单的形式,同时仍在执行我的原始程序所做的事情。

#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

我在这里查看了每个类似的答案。据我所知,我所有的框架都是正确的。我必须缺少一些简单而愚蠢的东西。为什么“playVideo”方法永远不会触发?唯一有效的情况是我将按钮直接添加到 self.view

最佳答案

UIImageView 默认将 userInteractionEnabled 保持为 false - 添加以下代码行即可。

_panel.userInteractionEnabled = true;

关于ios - UIButton 作为 subview 没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28185125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com