1. 程式人生 > >iPhone X 隱藏底部Home條

iPhone X 隱藏底部Home條

Home鍵指示器隱藏相關API

@interface UIViewController (UIHomeIndicatorAutoHidden)

// Override to return a child view controller or nil. If non-nil, that view controller's home indicator auto-hiding will be used. If nil, self is used. Whenever the return value changes, -setNeedsHomeIndicatorAutoHiddenUpdate should be called.
- (nullable UIViewController *)childViewControllerForHomeIndicatorAutoHidden API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos);

// Controls the application'
s preferred home indicator auto-hiding when this view controller is shown. - (BOOL)prefersHomeIndicatorAutoHidden API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos); // This should be called whenever the return values for the view controller's home indicator auto-hiding have changed. - (void)setNeedsUpdateOfHomeIndicatorAutoHidden API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos); @end

開啟自動隱藏功能

- (BOOL)prefersHomeIndicatorAutoHidden {
    return YES;
}

如果想手動控制隱藏功能,動態返回一個值,並且在更新的時候呼叫 setNeedsUpdateOfHomeIndicatorAutoHidden 方法

- (BOOL)prefersHomeIndicatorAutoHidden {
    return  _isHomeIndicatorHidden;
}
// 更新值時呼叫
_isHomeIndicatorHidden = NO;
[self setNeedsUpdateOfHomeIndicatorAutoHidden];

*注:呼叫方法隱藏時,Home條會在1~2秒後自動慢慢消失