背景:为了兼容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
``
网友评论