How to implement a scrollable UICollectionView inside a UIScrollView?

In shorts, my desired screen layout is basically a user profile (iOS 7 + Xcode 5). As a top-level view, I used UIScrollView. The reason is because I want all of its routines to scroll (viewing user information - a view with a profile image and some buttons that you see on the screen, and viewing a collection of photos - the one with a black background) when it scrolls.

enter image description here

The area with a black background will show user photos. I am wondering if I can use the UICollectionView here, or is there a better way to implement it. The UICollectionView in this case will not be able to scroll itself, it just shows all the cells, while the scroll operation is handled by the most external UIScrollView.

I am reading the following posts:

UICollectionView inside UIScrollView

UICollectionView in UIScrollView -> Scroll Order

iOS 7 Collection View inside scroll>

Some said it was impossible (or at least strange) to implement a UICollectionView inside a UIScrollView, because UIScrollView is a superclass of UICollectionView, which leads to unexpected behavior. Some said that this should be implemented differently (but I have not seen a clear proposal).

+8
ios ios7 uiscrollview uicollectionview
source share
1 answer

Yes, you can put a UICollectionView inside a UIScrollView . iOS fully supports nested scroll views with iOS 3.0 , and UICollectionView is a subclass of UIScrollView . For example, check out the App Store app on your iOS device. The screen scrolls vertically - it is either a UIScrollView or a UITableView (which itself is a subclass of UIScrollView ). And each row of icons scrolls horizontally - each row has a UICollectionView .

However, it is not clear why you need to put the collection view in a scroll. It looks like you just want the photo view to be viewed, so just browse the photos as a collection. Why do you need to scroll the collection view?

UPDATE

Just use the collection view. Set the section header 0 to the profile information view. You do not need to scroll.

If you put all the photos in one section, you can customize the title in your storyboard without a code. If you use multiple sections, you need to implement collectionView:layout:referenceSizeForHeaderInSection: in your deletion and collectionView:viewForSupplementaryElementOfKind:atIndexPath: in your data source.

+7
source share

All Articles