본문 바로가기

Swift

Rotation을 위한 shouldInvalidateLayoutForBoundsChange 테스트

Rotation을 위해서 여러가지 테스트를 해 보았지만 일단 사용할 필요성은 못 느끼는 것으로 결론났다.

Rotation에는 그냥 viewWillTransitionToSize를 쓰는 것이 갑이다.



    override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool {
        
        // 이 메소드는 말그대로 Bounds가 변할 때 호출된다. 그러므로 rotation뿐만 아니라 화면 스크롤 시에도 무지하게 발생한다.
        // 오히려 rotation의 경우에는 호출되지 않는 경우가 있다.
        
        // debugPrint("5 newBounds=\(newBounds)")
        if (previousBounds == nil || previousBounds!.width != newBounds.width) {
            
            debugPrint("5-1")
            cellSize = newBounds.size
            debugPrint("5-2")
            previousBounds = newBounds
            debugPrint("5-3")
            
            // 가로든 세로든 newBounds.width가 직전 모드의 세로 길이이므로 - 물론 Inset이 있을 때에는 이를 고려해야 함
            currentIndex = newBounds.origin.y / newBounds.width

            return true
        }
        else {
            return false
        }
    }