多重構造の中で UIScrollView.scrollsToTop を一気に設定するやつ

  • 2
    Like
  • 0
    Comment
UIView.swift
import UIKit

extension UIView {

    func findScrollViews() {
        if self is UIScrollView {
            print(#function, "scrollsToTop: \((self as! UIScrollView).scrollsToTop), \(self.hash), \(self.frame)")
        }
        for v in subviews {
            v.findScrollViews()
        }
    }

    func resetScrollsToTop(_ targetScrollView: UIScrollView) {
        if self is UIScrollView {
            (self as! UIScrollView).scrollsToTop = self == targetScrollView
        }
        for v in subviews {
            v.resetScrollsToTop(targetScrollView)
        }
    }

}
view.resetScrollsToTop(currentScrollView)

// 検証
view.findScrollViews()
print("-----")