【发布时间】:2015-01-28 05:16:44
【问题描述】:
我在UIView 内部有一个UIButton,在一个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
我在这里查看了所有类似的答案。据我所知,我所有的框架都是正确的。一定有一些我想念的简单而愚蠢的东西。为什么“playVideo”方法永远不会触发?唯一有效的情况是我将按钮直接添加到self.view。
【问题讨论】:
标签: ios objective-c uiview uibutton