在UIScrollView上的UIImageView上的UIButton(不工作)

时间:2013-05-31 02:46:42

标签: iphone ios uibutton

UIButton上的UIImageView UIScrollView。但是,按钮不起作用(按钮不响应并写入button.userInteractionEnabled = YES)。为什么呢?

pagingView = [[InfinitePagingView alloc] initWithFrame:CGRectMake(0.f, 0.f,            self.view.frame.size.width, self.view.frame.size.height - naviBarHeight)];
pagingView.delegate = self;
[self.view addSubview:pagingView];

UIImage *image1 = [UIImage imageNamed:[NSString stringWithFormat:@"1.jpg"]];
page1 = [[UIImageView alloc] initWithImage:image1];
page1.frame = CGRectMake(0, 0, pagingView.frame.size.width * 0.8, pagingView.frame.size.height * 0.8);
page1.userInteractionEnabled = YES;
page1.contentMode = UIViewContentModeScaleAspectFit;

btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(100, 200, 50, 50);
[btn addTarget:self action:@selector(toControl) forControlEvents:UIControlEventTouchUpInside];
[page1 addSubview:btn];
[pagingView addPageView:page1];

3 个答案:

答案 0 :(得分:1)

尝试使用以下内容:

page1.userInteractionEnabled = NO;
btn.userInteractionEnabled = YES;

还要确保您的按钮不在ImageView的框架之外。 还有一件事是你不直接将你的按钮添加到你的视图而不是你的imageview。

答案 1 :(得分:0)

试试这个(测试):

page1.userInteractionEnabled = YES;
btn.userInteractionEnabled = YES;

答案 2 :(得分:0)

尝试这个

pagingView = [[InfinitePagingView alloc] initWithFrame:CGRectMake(0.f, 0.f,            self.view.frame.size.width, self.view.frame.size.height - naviBarHeight)];
pagingView.delegate = self;
[self.view addSubview:pagingView];

UIImage *image1 = [UIImage imageNamed:[NSString stringWithFormat:@"1.jpg"]];
page1 = [[UIImageView alloc] initWithImage:image1];
page1.frame = CGRectMake(0, 0, pagingView.frame.size.width * 0.8, pagingView.frame.size.height * 0.8);
page1.userInteractionEnabled = YES;
page1.contentMode = UIViewContentModeScaleAspectFit;
[pagingView addPageView:page1];

btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(100, 200, 50, 50);
[btn addTarget:self action:@selector(toControl) forControlEvents:UIControlEventTouchUpInside];
[page1 addSubview:btn];