scrollView上的按钮丢失动作事件

时间:2014-05-23 01:43:53

标签: ios uiscrollview uibutton

如何在此按钮上获取操作事件?

self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.scrollView];

UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(0, 0, 32, 32);
backButton.adjustsImageWhenHighlighted = YES;
[backButton setImage:backButtonImage forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[_scrollView addSubview:backButton];

1 个答案:

答案 0 :(得分:0)

你的代码很好。实现这个功能

- (void)backButtonAction:(id)sender
{
    NSLog(@"backButton pressed");
}

如果没有调用,请检查scroolView的userInteractionEnabled并设置为YES

_scrollView.userInteractionEnabled = YES;