How do I scroll with a fixed part of the screen in iOS?

Asked 2 years ago, Updated 2 years ago, 30 views

I am making an app for iPad with xcode8&swift.
I use Storyboard & Autolayout.
iOS 10.x is the target.

UITableView is placed in the UIScrollView to display a larger table than the screen on both the top, bottom, left and right, and scroll up, bottom, left and right to display.(↓Image like this)

Scroll the entire table

Currently, I'm trying to scroll through the second row or later with only a part of the screen (for example, the first row) fixed to the left and right, but I don't know how to achieve it.(↓Image like this)

Some fixed scrolling

Could you please let me know if anyone knows anything?
It doesn't matter if you look here or this book.
Thank you for your cooperation.

swift ios

2022-09-29 22:23

2 Answers

I don't think UITableView and UIScrollView are very suitable.It's not impossible, but it's very difficult because there are so many things to control.

Why don't you consider using UICollectionView?UICollectionView has a property called sectionHeadersPinToVisibleBounds, so if that allows you to achieve the desired behavior, that would be the easiest.

Otherwise, you can customize the layout of the UICollectionView to achieve a fixed header.
Specifically, layoutAttributesForSupplementaryViewOfKind(elementKind:atIndexPath:) always sticks to the left edge of the scroll (=contentOffset.x).

It's a little old, but I think this article will be helpful.
http://dativestudios.com/blog/2015/01/10/collection_view_sticky_headers/


as an existing library that can achieve similar screens fairly versatile. https://github.com/stuffrabbit/SwiftSpreadsheet

is available.This provides a custom layout for UI like spreadsheet using UICollectionView.Even if you can't use it as it is, I think the code will be very helpful.

The other one I made is
https://github.com/kishikawakatsumi/SpreadsheetView

That's why.This is accomplished in a combination of UIScrollView.Compared to the above libraries, you will find that the code is quite complicated.

I think it's better to use these as a reference to choose the architecture that matches what you want to do.


2022-09-29 22:23

Wouldn't it be better to separate the name view from the other view?
You can set up a UIScrollViewDelegate and communicate scrolling to each other.


2022-09-29 22:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.