[英]iOS UIScrollView in UIWindow
I currently am making an iOS project in which I have a UIScrollView
as a direct subview of a UIWindow
(using [window addSubview:scrollView];
). 我目前正在制作一个iOS项目,其中有一个
UIScrollView
作为UIWindow
的直接子视图(使用[window addSubview:scrollView];
)。 The window's frame and its content are being set properly, and the contentSize
is set to be bigger than the window's frame. 窗口的框架及其内容已正确设置,并且
contentSize
设置为大于窗口的框架。 When I try to scroll the UIScrollView, it doesn't scroll at all. 当我尝试滚动UIScrollView时,它根本不会滚动。 Both
scrollEnabled
and pagingEnabled
are set to YES
, but the scrollview doesn't scroll, which leads me to believe that the touch/scroll events are not even being received by the scroll view. scrollEnabled
和pagingEnabled
都设置为YES
,但是scrollview不滚动,这使我相信滚动视图甚至没有接收到触摸/滚动事件。 The window has a UITapGestureRecognizer
added to it if it makes any difference. 如果该窗口有所不同,则该窗口将添加一个
UITapGestureRecognizer
。 Do I need to somehow forward the swipe events to the UIScrollView
, or is there a different reason that it's not scrolling? 我是否需要以某种方式将滑动事件转发到
UIScrollView
,还是有其他原因导致其不滚动?
EDIT: Here's some code. 编辑:这是一些代码。
float count=ceil([self.msgArray count]/2); //msgArray has length of 3+, NSLog()'d and confirmed.
float contentHeight=97.5 * count;
[dataScrollView setContentSize:CGSizeMake(320,contentHeight)];
dataScrollView.userInteractionEnabled=YES;
dataScrollView.pagingEnabled=YES;
dataScrollView.scrollEnabled=YES;
dataScrollView.clipsToBounds=YES; //Have also tried with this set to NO, or not set at all.
//Add subviews to dataScrollView.
EDIT: Here's some more info. 编辑:这是更多信息。 contentHeight is 195.00 when logged.
记录时contentHeight为195.00。 I've removed the delegate method and I am back to using direct subviews of the scroll view.
我删除了委托方法,回到了滚动视图的直接子视图。 The window's height is 97.50.
窗口的高度为97.50。
EDIT: I've also removed the UITapGestureRecognizer from the UIWindow, but the scrollview still doesn't scroll. 编辑:我还从UIWindow中删除了UITapGestureRecognizer,但是scrollview仍然无法滚动。
Ah, the UITapGestureRecognizer
! 啊,
UITapGestureRecognizer
! This might be a bug that took me hours to figure out in my own project. 这可能是一个错误,使我花了数小时才能确定自己的项目。 Is its
cancelsTouchesInView
property set to NO
like it should be? 是否将其
cancelsTouchesInView
属性设置为NO
呢? ( YES
is the default... It can really throw you off if you're not expecting it.) (默认
YES
是”。如果您不期望它,它确实会让您失望。)
Just log the scrollview bounds width/height. 只需记录scrollview边界的宽度/高度。 The content height you are setting should be greater than the scrollview height.
您要设置的内容高度应大于滚动视图的高度。 If its more then the scroll view automatically enables its scrolling.
如果更多,则滚动视图将自动启用其滚动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.