How to implement non-scrollable UICollectionView inside UIScrollView?
In shorts, my desired screen layout is basically a user profile (iOS 7 + Xcode 5). I used UIScrollView as the top level view. The reason is that I want all its subviews to scroll (user info view – the view with a profile image and some buttons you see on the screen, and the photos collection view – the one with black background) when it is scrolled.
The region with black background will show user photos. I’m wondering if I could use a UICollectionView here, or there’s a better way to implement it. The UICollectionView in this case shouldn’t be able to scroll itself, it just shows all cells, while the scrolling work is handled by the outermost UIScrollView.
I read following posts:
UICollectionView inside of UIScrollView
UICollectionView in UIScrollView -> Scroll Order
iOS 7 Collection View inside Scroll View
Some said it’s not possible (or at least, weird) implemeting UICollectionView inside UIScrollView because UIScrollView is UICollectionView’s superclass which leads to unexpected behaviour. Some said it should be implemented in another way (but I didn’t see a clear suggestion).
Solutions Collect From Internet About “How to implement non-scrollable UICollectionView inside UIScrollView?”
Yes, you can put a
UICollectionView inside a
UIScrollView. iOS has fully supported nested scroll views since 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’s either a
UIScrollView or a
UITableView (which is itself a subclass of
UIScrollView). And each row of icons scrolls horizontally – each row is a
However, it’s not clear why you need to put a collection view inside a scroll view. It sounds like you only want the photos view to scroll, so just make the photos view be a collection view. Why do you need to put the collection view inside a scroll view?
Just use a collection view. Set the header of section 0 to the profile info view. You don’t need a scroll view.
If you put all the photos in one section, you can set up the header in your storyboard with no code. If you use multiple sections, you’ll need to implement
collectionView:layout:referenceSizeForHeaderInSection: in your delegate and
collectionView:viewForSupplementaryElementOfKind:atIndexPath: in your data source.
- Interface Builder broken on Framework projects using Cocoapods 1.0
- Making two storyboards for iOS (iPhone and iPad)
- Develop iPhone application remotely?
- Don't have the pictures from directory on CollectionView
- Parse Data into NSTableView
- How to get location in background even after phone restart in swift?
- How to load storyboard file from custom bundle in IOS app?
- iOS 6 – can i return data when i unwind a segue?
- Programmatically scroll a UIScrollView
- Swift – Get data from Alamofire POST request
- singleton in objective c
- How to Send data between view controllers StoryBoard Xcode
- in Split view controller didSelect method not working
- Take a screenshot using code
- How String Comparison happens in Swift