Advertisement
Guest User

Untitled

a guest
May 17th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  UIViewController+SafeArea.m
  3. //  Pivot Surveys
  4. //
  5. //  Created by Anthony Gorb on 5/17/18.
  6. //  Copyright © 2018 MEV, LLC. All rights reserved.
  7. //
  8.  
  9. #import "UIViewController+SafeArea.h"
  10. #import "UIView+FrameAdditions.h"
  11.  
  12. @implementation UIViewController (SafeArea)
  13.  
  14. #pragma mark - Private
  15.  
  16. - (UIWindow *)keyWindow {
  17.     return UIApplication.sharedApplication.keyWindow;
  18. }
  19.  
  20. - (CGFloat)topInset {
  21.     if (@available(iOS 11.0, *)) {
  22.         return [self keyWindow].safeAreaInsets.top;
  23.     }
  24.     return 0;
  25. }
  26.  
  27. - (CGFloat)bottomInset {
  28.     if (@available(iOS 11.0, *)) {
  29.         return [self keyWindow].safeAreaInsets.bottom;
  30.     }
  31.     return 0;
  32. }
  33.  
  34. #pragma mark - Public
  35.  
  36. - (void)addTopInsetToView:(UIView *)view {
  37.     if (@available(iOS 11.0, *)) {
  38.         view.y += [self topInset];
  39.     }
  40. }
  41.  
  42. - (void)removeTopInsetFromView:(UIView *)view {
  43.     if (@available(iOS 11.0, *)) {
  44.         view.y -= [self topInset];
  45.     }
  46. }
  47.  
  48. - (void)addBottomInsetToView:(UIView *)view {
  49.     if (@available(iOS 11.0, *)) {
  50.         view.y += [self bottomInset];
  51.     }
  52. }
  53.  
  54. - (void)removeBottomInsetFromView:(UIView *)view {
  55.     if (@available(iOS 11.0, *)) {
  56.         view.y -= [self bottomInset];
  57.     }
  58. }
  59.  
  60. - (void)addTopInsetToViewHeight:(UIView *)view {
  61.     if (@available(iOS 11.0, *)) {
  62.         view.height += [self topInset];
  63.     }
  64. }
  65.  
  66. - (void)removeTopInsetFromViewHeight:(UIView *)view {
  67.     if (@available(iOS 11.0, *)) {
  68.         view.height -= [self topInset];
  69.     }
  70. }
  71.  
  72. - (void)addBottomInsetToViewHeight:(UIView *)view {
  73.     if (@available(iOS 11.0, *)) {
  74.         view.height += [self bottomInset];
  75.     }
  76. }
  77.  
  78. - (void)removeBottomInsetFromViewHeight:(UIView *)view {
  79.     if (@available(iOS 11.0, *)) {
  80.         view.height -= [self bottomInset];
  81.     }
  82. }
  83.  
  84. @end
  85.  
  86.  
  87. // then in viewController
  88. - (void)addSafeAreaSupport
  89. {
  90.     [self addTopInsetToView:self.topLogoView];
  91.     [self addTopInsetToView:self.formContainerView];
  92.     [self removeTopInsetFromViewHeight:self.formContainerView];
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement