簡體   English   中英

UIScrollView上的UIImageView上的UIButton(不起作用)

[英]UIButton(not working) on the UIImageView on the UIScrollView

我在UIScrollViewUIImageView上有UIButton 但是,按鈕不起作用(按鈕不響應,並寫了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];

嘗試使用以下內容:

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

還要確保您的按鈕沒有超出ImageView的框架。 還有一件事,為什么不直接將按鈕添加到視圖而不是圖像視圖。

試試這個(已測試 ):

page1.userInteractionEnabled = YES;
btn.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;
[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];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM