ios


Sticking a TableView Header to the top, causes the header to not “interact” when user scrolls down


I am sticking my UITableView header to the top when user scrolls down the UITableView. The header view itself is a UIButton which does something when clicked.
The button responds well to touches when contentOffset Y is 0. However when the user scrolls down, the button still sticks to the top but every touches "passes through" it.
Here is my code to stick the header to the top:
var offsetY = scrollView.contentOffset.y;
var headerContentView: UIView = self.tableView.tableHeaderView?.subviews[0] as UIView;
headerContentView.frame = CGRect(x: 0, y: max(0, offsetY), width: headerContentView.bounds.width, height: headerContentView.bounds.height);
Thanks.
If you're going to be moving the view around yourself, don't use tableHeaderView at all. Instead add it as a subview of the table view directly and keep a reference to it. Then in scrollViewDidScroll: layout the view's Y offset according to scrollView.contentOffset.y.
You may need to trigger this layout in viewDidLoad so that it appears properly before any scroll events happen. If the view shouldn't overlap the top cell when the table is scrolled to the top, set the view's height to the table's contentInset's top.

Related Links

Xcode 7.3.1: New project templates' screen's text is overlapped
Swift 3.0 Image Sets
Opening Instagram app from a link on iOS
Particle system is seen as black from certain angles
Xcode lost connection to iPhone 6
Blurry scale on Safari Mobile / iOS
Play all songs in music
UIWebView not rendering properly after orientation change
dispatch_once conversion Swift 3
Collection View (Creating a Draggable UICollectionViewCell) Fatal Error
IOS 10 setting MPNowPlayingInfoPropertyPlaybackRate to 0 blanks the lock screen
TableView and progress bar
Event to do something when the user slides up on the last page in UIPageViewController swift
Ambiguous reference to member 'collectionView(_:numberOfItemsInSection:)' when reloading collection view data
How to override constraints that are set in parent class
Vertical Divider Between Tabs

Categories

HOME
azure
asp.net-mvc
asp.net-identity
module
android-activity
stack
xquery
svg.js
predictionio
player-swift
binary-search
copy-paste
wso2ei
oracle-ucm
frequency
installer
accumulo
jgit
collision
spark-graphx
aspdotnetstorefront
py4j
ratchet-2
ruamel.yaml
solarwindslem
popupwindow
jsplumb
scatter-plot
azure-api-apps
tensor
gosublime
doctrine-odm
haxm
querydsl
gradient-descent
mask
response
symfony-process
plasticscm
phasset
openwebanalytics
website-hosting
domdocument
facebook-canvas
curly-braces
blocking
hapi.js
directsound
ocsp
struts1
webdeploy-3.5
menustrip
accounts
jca
administrator
asp.net-authorization
sqlj
wand
document-ready
aldryn
push-api
hypervisor
heroku-toolbelt
esky
tabbar
viennacl
telescope
node-orm2
gem
vendor
scribe
applicationstate
misra
ratingbar
datacontractserializer
aps
team-explorer-everywhere
textselection
requiredfieldvalidator
ramdisk
data-dictionary
nawk
apache-commons-dbcp
nsimageview
domain-mapping
lungojs
documentviewer
quilt
settings.bundle
postgresql-8.1
springboard
retain
unitils
remote-control
gendarme
crc-cards
mud

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App