【发布时间】:2014-04-29 03:10:48
【问题描述】:
我的问题是当我分页到我的子视图时我的按钮不起作用。 ScrollView 上的按钮是否一切正常。
主视图控制器
- (void)viewDidLoad
{
[super viewDidLoad];
self.sView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
self.sView.contentSize = CGSizeMake(self.sView.frame.size.width,
self.sView.frame.size.height*2);
self.sView.pagingEnabled=YES;
self.sView.backgroundColor = [UIColor redColor];
self.sView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:self.sView];
self.sVC = [[StartViewController alloc] initWithNibName:nil bundle:nil];
self.sVC.view.frame = CGRectMake(0, 0, self.sView.frame.size.width, self.sView.frame.size.height);
[self.sView addSubview:self.sVC.view];
[self addChildViewController:self.sVC];
}
子视图控制器
- (void)viewDidLoad
{
[super viewDidLoad];
self.playView = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
self.playView.backgroundColor = [UIColor greenColor];
[self.view addSubview:self.playView];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(50, 50, 50, 50)];
btn.backgroundColor = [UIColor whiteColor];
[btn addTarget:self action:@selector(show:) forControlEvents:UIControlEventTouchUpInside];
[btn setUserInteractionEnabled:YES];
[self.playView addSubview:btn];
}
- (void)show:(id)sender
{
NSLog(@"--test");
}
【问题讨论】:
-
只是想了解一下,您是否将 SubViewController 的视图作为子视图添加到 MainViewController 中? SubViewController 的类实际上是 StartViewController 吗?
-
正确,我的 mainView 是一个滚动视图,当我向下滚动时,我看到的是带有按钮的子视图。
标签: ios iphone objective-c uiscrollview uibutton