나는 UIImageView
안에 UIView
안에있는 UIButton
의 접촉에 응답하지 않습니다. 나는 이유를 알 수 없다. 나는 원래의 프로그램이하는 일을하면서 코드를 가장 단순한 형태로 분해했다.서브 뷰로 응답하지 않는 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
에 추가하는 것입니다.
이것이 효과가 있습니다! 고맙습니다. – user1118374
그래서 superview에서 사용자 상호 작용이 사용 중지 된 경우 하위보기도 사용 중지됩니다. – user1118374
네 말이 맞아. –