简体   繁体   中英

iOS - Some UIViews inside UIScrollview not receiving touches

I am programmatically adding views to UIScrollView. Problem is only those views are responding to touch that are initially visible on the iPad. If I scroll to views that are outside iPad's screen initially and click them, nothing happens. Following is how my view controller looks like; note that I am not using Auto Layout.

在此输入图像描述

And following is how I am setting the touch for my custom view that is subclass of UIButton:

[myView addTarget:self action:@selector(handlePanelClick:) forControlEvents:UIControlEventTouchUpInside];

With the help of @Jelly comment, I noticed that the view inside scrollview that holds all the subviews was not being resized properly. Following is how it looked initially ... when visible subviews on screen properly handled touch.

在此输入图像描述

And following is how it looked when I scrolled to bottom ... note that PanelsView is not resized properly to contain all the subviews:-

在此输入图像描述

Looks like I only needed to adjust the height of PanelsView to match its child ( viewPanelContainer ) height which is what i did in below line after panelsView finished its drawing:-

_panelsView.frame = CGRectMake(0, 0, _panelsView.frame.size.width, _panelsView.viewPanelContainer.frame.size.height);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM