美文网首页
OC:Masonry留出安全区

OC:Masonry留出安全区

作者: 春暖花已开 | 来源:发表于2019-05-29 19:33 被阅读0次

背景:为了兼容iPhone X系列,避免写过累死 kIphoneXHeight 的代码,这个分类就应运而生了。

#import <UIKit/UIKit.h>

#import "Masonry.h"

NS_ASSUME_NONNULL_BEGIN

@interface UIViewController (MZMasonry)

@property (nonatomic, strong, readonly) MASViewAttribute *mz_top;
@property (nonatomic, strong, readonly) MASViewAttribute *mz_bottom;

@end

NS_ASSUME_NONNULL_END


#import "UIViewController+MZMasonry.h"

@implementation UIViewController (MZMasonry)

- (MASViewAttribute *)mz_top {
    if (@available(iOS 11.0, *)) {
        return self.view.mas_safeAreaLayoutGuideTop;
    }
    
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
    return self.mas_topLayoutGuide;
#pragma clang diagnostic pop
}

//@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuide NS_DEPRECATED_IOS(8.0, 11.0);
//@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideBottom NS_AVAILABLE_IOS(11.0);
- (MASViewAttribute *)mz_bottom {
    if (@available(iOS 11.0, *)) {
        return self.view.mas_safeAreaLayoutGuideBottom;
    }
    
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
    return self.mas_bottomLayoutGuide;
#pragma clang diagnostic pop
}

@end
``

相关文章

网友评论

      本文标题:OC:Masonry留出安全区

      本文链接:https://www.haomeiwen.com/subject/lzjutctx.html