Problem deriving custom object from UIScrollView

Rick Aurbach

macOS 10.12.6 / Xcode 8.3ß6 / Swift 4 / developing for iOS

I am working on a custom object which derives from UIScrollView (at least for now...see below). For initial testing, I am placing it on a view of a UINavigationController panel.
When I run the test application, I find that the contentOffset of my scrollView-subclass is being set to (0.0, -64.0). By putting a breakpoint in contentOffset (didSet), I was able to capture the following stack trace where contentSize was set:

Thread 1 Queue : (serial)
#0 0x000000010bf4fe59 in SelectorStrip.contentOffset.didset at /Users/rlaurb/Projects/RLAUIObjects/RLAUIObjects/SelectorStrip.swift:67
#1 0x000000010bf4fe33 in SelectorStrip.contentOffset.setter ()
#2 0x000000010bf4fd48 in @objc SelectorStrip.contentOffset.setter ()
#3 0x000000010cbab956 in -[UIViewController _setNavigationControllerContentInsetAdjustment:] ()
#4 0x000000010cbf3b5a in -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] ()
#5 0x000000010cbf3ebc in -[UINavigationController _layoutViewController:] ()
#6 0x000000010cbf474a in -[UINavigationController _updateScrollViewFromViewController:toViewController:] ()
#7 0x000000010cbe584d in -[UINavigationController _startCustomTransition:] ()
#8 0x000000010cbf5967 in -[UINavigationController _startDeferredTransitionIfNeeded:] ()
#9 0x000000010cbf6b41 in -[UINavigationController __viewWillLayoutSubviews] ()
#10 0x000000010cde860c in -[UILayoutContainerView layoutSubviews] ()
#11 0x000000010cad555b in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] ()
#12 0x000000010fa3e904 in -[CALayer layoutSublayers] ()
#13 0x000000010fa32526 in CA::Layer::layout_if_needed(CA::Transaction*) ()
#14 0x000000010fa323a0 in CA::Layer::layout_and_display_if_needed(CA::Transaction*) ()
#15 0x000000010f9c1e92 in CA::Context::commit_transaction(CA::Transaction*) ()
#16 0x000000010f9ee130 in CA::Transaction::commit() ()
#17 0x000000010ca3d5e7 in _afterCACommitHandler ()
#19 0x000000010ee05687 in __CFRunLoopDoObservers ()
#20 0x000000010edea720 in __CFRunLoopRun ()
#21 0x000000010edea016 in CFRunLoopRunSpecific ()
#22 0x0000000112b25a24 in GSEventRunModal ()
#23 0x000000010ca12134 in UIApplicationMain ()
#24 0x000000010be9a6e7 in main at /Users/rlaurb/Projects/RLAUIObjects/RLAUIObjectsExample/RLAUIObjectsExample/AppDelegate.swift:12
#25 0x0000000110d8465d in start ()
So it appears that contentOffset is being set by layout actions of the UINavigationController, even though my custom class only scrolls horizontally and occupies only a small part of the screen.

Several questions come to mind:
  1. Is this a bug? It doesn't seem right that the UINavigationControlller should adjust the scrolling context of something that is well below the top layout guide.
  2. How do I understand this behavior?
  3. How can I work around this behavior (regardless of it being correct or incorrect)? Is there some InterfaceBuilder setting I'm missing? Or can I shield the UIScrollView by embedding it in an otherwise innocuous UIView?

All thoughts and/or suggestions will be most welcome.


Rick Aurbach