Date
Sep. 8th, 2024
 
2024年 8月 6日

Post: iOS 面试题: viewWillLayoutSubView

iOS 面试题: viewWillLayoutSubView

Published 12:10 Oct 14, 2015.

Created by @ezra. Categorized in #Programming, and tagged as #iOS.

Source format: Markdown

Table of Content

最近遇到和看到的一些面试题。

viewWillLayoutSubView 你总是知道的。

横竖屏切换的时候,系统会响应一些函数,其中 viewWillLayoutSubviewsviewDidLayoutSubviews。

- (void)viewWillLayoutSubviews {
    [self _shouldRotateToOrientation:(UIDeviceOrientation)[UIApplication sharedApplication].statusBarOrientation];
}

- (void)_shouldRotateToOrientation:(UIDeviceOrientation)orientation {
    if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
        // 竖屏
    } else {
       // 横屏
    }
}

通过上述一个函数就知道横竖屏切换的接口了。

注意: viewWillLayoutSubviews 只能用在ViewController里面,在view里面没有响应。

Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
程序猿、设计师、奇怪的博主。
苹果死忠、热爱色彩斑斓的世界。
如有意向请随时 与我联系