1

私はUIButton上に持ってUIImageViewUIScrollViewます。ただし、ボタンが機能しません(ボタンが反応せず、書き込みました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];
4

3 に答える 3

1

以下を使用してみてください:

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

また、ボタンが ImageView のフレームから外れていないことを確認してください。もう1つ、イメージビューの代わりにボタンをビューに直接追加しないでください。

于 2013-05-31T04:06:57.510 に答える
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];
于 2013-05-31T06:17:12.313 に答える
0

これを試してください(テスト済み):

page1.userInteractionEnabled = YES;
btn.userInteractionEnabled = YES;
于 2013-05-31T05:59:34.343 に答える