[英]iOS - Some UIViews inside UIScrollview not receiving touches
I am programmatically adding views to UIScrollView. 我以编程方式向UIScrollView添加视图。 Problem is only those views are responding to touch that are initially visible on the iPad.
问题是只有那些视图响应最初在iPad上可见的触摸。 If I scroll to views that are outside iPad's screen initially and click them, nothing happens.
如果我最初滚动到iPad屏幕外的视图并单击它们,则没有任何反应。 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: 以下是我为自定义视图设置触摸的方式,该视图是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. 在@Jelly评论的帮助下,我注意到滚动视图中包含所有子视图的视图没有正确调整大小。 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:- 以下是我滚动到底部时的样子...请注意PanelsView未正确调整大小以包含所有子视图: -
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的高度以匹配其子( viewPanelContainer )高度,这是我在panelsView完成绘图后在下面的行中所做的: -
_panelsView.frame = CGRectMake(0, 0, _panelsView.frame.size.width, _panelsView.viewPanelContainer.frame.size.height);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.