1

Erica Sadun がクックブックの例 Ch07-11 で次のことを行う理由 (viewDidLayoutSubviews で viewDidAppear を呼び出す) を理解するのに苦労しています。おそらく、2 つのメソッドは代わりに別のメソッドを呼び出す必要がありますか?

参照: https://github.com/erica/iOS-5-Cookbook/tree/master/C07

- (void) viewDidAppear:(BOOL)animated
{
    scrollView.frame = self.view.bounds;
    scrollView.center = CGRectGetCenter(self.view.bounds);

    if (imageView.image)
    {
        float scalex = scrollView.frame.size.width / imageView.image.size.width;
        float scaley = scrollView.frame.size.height / imageView.image.size.height;
        scrollView.zoomScale = MIN(scalex, scaley);
        scrollView.minimumZoomScale = MIN(scalex, scaley);
    }
}

- (void) viewDidLayoutSubviews
{
    [self viewDidAppear:NO];
}

理由はありますか?

4

2 に答える 2

3

これは私には完全に間違っているようです。これらのメソッドが呼び出されたときに UIKit に処理させます。

代わりにこれを行います:

- (void)viewDidAppear:(BOOL)アニメーション {
    [super viewDidAppear:animated]; // 常にこれで super を呼び出します!!!

    [self doSomeCustomLayoutStuff]; // これは実際には必要ないと思います。viewWillLayoutSubviews はサブビューをレイアウトするためのもので、iOS 5 以降では自動的に呼び出されます。

}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];

    [self doSomeCustomLayoutStuff];
}

- (void)doSomeCustomLayoutStuff {
    scrollView.frame = self.view.bounds;
    scrollView.center = CGRectGetCenter(self.view.bounds);

    もし (imageView.image)
    {
        float scalex = scrollView.frame.size.width / imageView.image.size.width;
        float scaley = scrollView.frame.size.height / imageView.image.size.height;
        scrollView.zoomScale = MIN(scalex、scaley);
        scrollView.minimumZoomScale = MIN(scalex、scaley);
    }
}
于 2013-10-03T14:31:16.630 に答える