简体   繁体   中英

UIScrollView on top of UIView (XIB) and scrollview will not scroll

In my xib I created a UIView.

I added a child to that UIView which was a UIScrollView. The scrollView will not scroll.

BUT If I drag the UIScrollView out of the UIView so they are on the same level then it will scroll as expected.

So why does my scrollview stop scrolling when it is inside a UIView on my XIB.

Is this a bug or is there something more I need to do to get the scrollview scrolling while a child of a UIView.

Many Thanks, -Code

According to the Apple documentation on scroll views..

The scroll view must know the size of the content view so it knows when to stop scrolling; by default, it “bounces” back when scrolling exceeds the bounds of the content.

Probably, you should set it's contentSize:

 [scrollView setContentSize:CGSizeMake(320, 480)];

Since your scrollView is a child of your view, you must set it's content size smaller than your view.

Also, don't forget to set your scroll view enabled.

 [scrollView setEnabled:YES];

设置滚动的内容大小... scroll.contentSize= CGSizeMake(320,2000)

Check whether the container UIView has userInteractionEnabled property is FALSE. This is the only reason, it will not allow you to scroll while scrollview is added to any UIView.

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