まだどこにもないアプリを作る

アプリ開発でつまづいたところなどを中心に記事にして行きます。

swift メモ備忘録 scrollViewの.zoomScaleでエラー

swift scrollViewの.zoomScaleでエラー

 

warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available.

 

まだScrollViewが準備できていないときに

scrollView.zoomScaleで取得するとこのエラーが出る。

viewForZoomingの中で普通に取得するとエラーになってしまう。

ので

下記のようにDispatchQueue.main.asyncAfter(deadline: .now()+0.5) で遅延して取得すればなんかうまくいきます。

 

@objc func viewForZooming(in scrollView: UIScrollView) -> UIView? {

        

        DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {

            print(self.scrollView.zoomScale)

        }

}