Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // UIViewController+SafeArea.m
- // Pivot Surveys
- //
- // Created by Anthony Gorb on 5/17/18.
- // Copyright © 2018 MEV, LLC. All rights reserved.
- //
- #import "UIViewController+SafeArea.h"
- #import "UIView+FrameAdditions.h"
- @implementation UIViewController (SafeArea)
- #pragma mark - Private
- - (UIWindow *)keyWindow {
- return UIApplication.sharedApplication.keyWindow;
- }
- - (CGFloat)topInset {
- if (@available(iOS 11.0, *)) {
- return [self keyWindow].safeAreaInsets.top;
- }
- return 0;
- }
- - (CGFloat)bottomInset {
- if (@available(iOS 11.0, *)) {
- return [self keyWindow].safeAreaInsets.bottom;
- }
- return 0;
- }
- #pragma mark - Public
- - (void)addTopInsetToView:(UIView *)view {
- if (@available(iOS 11.0, *)) {
- view.y += [self topInset];
- }
- }
- - (void)removeTopInsetFromView:(UIView *)view {
- if (@available(iOS 11.0, *)) {
- view.y -= [self topInset];
- }
- }
- - (void)addBottomInsetToView:(UIView *)view {
- if (@available(iOS 11.0, *)) {
- view.y += [self bottomInset];
- }
- }
- - (void)removeBottomInsetFromView:(UIView *)view {
- if (@available(iOS 11.0, *)) {
- view.y -= [self bottomInset];
- }
- }
- - (void)addTopInsetToViewHeight:(UIView *)view {
- if (@available(iOS 11.0, *)) {
- view.height += [self topInset];
- }
- }
- - (void)removeTopInsetFromViewHeight:(UIView *)view {
- if (@available(iOS 11.0, *)) {
- view.height -= [self topInset];
- }
- }
- - (void)addBottomInsetToViewHeight:(UIView *)view {
- if (@available(iOS 11.0, *)) {
- view.height += [self bottomInset];
- }
- }
- - (void)removeBottomInsetFromViewHeight:(UIView *)view {
- if (@available(iOS 11.0, *)) {
- view.height -= [self bottomInset];
- }
- }
- @end
- // then in viewController
- - (void)addSafeAreaSupport
- {
- [self addTopInsetToView:self.topLogoView];
- [self addTopInsetToView:self.formContainerView];
- [self removeTopInsetFromViewHeight:self.formContainerView];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement