前两天iOS11正式版的推送随之而来的是Xcode9,今年Apple搞十周年多推送一款手机--iPhoneX,虽未上市,但是这种手机屏幕对于我们开发者来说就有点不和谐了。随着模拟器iPhone X出现,适配势在必行了。不多说了,讲点实际的。
手头项目一运行没有自定义navigation的地方很好,没啥问题但是涉及到自定义navigation的时候问题就来了,平时喜欢随便写个64的人悲剧了,我倒是平时习惯好点(但也只是好一点点,放在PCH文件中统一管理)
于是只要稍稍改一下
我特地把这些常用的放在公共的地方
//界面上面适配主要是iPhone X的状态栏高度是44而正常是20和tabbar的高度是83(多了34),而正常的高度是49
#define StatusRectH [[UIApplication sharedApplication] statusBarFrame].size.height//状态栏
#define NavRectH self.navigationController.navigationBar.frame.size.height////标题栏还是44
//navi总高度(非控制器专用)
#define NavH_view [DRFunctionUnit getNavVC].navigationBar.frame.size.height + StatusRectH
#define VHeight (SCREEN_HEIGHT - StatusRectH - NavRectH)
#define CURRENT_SIZE(_size) _size / 320.0 * SCREEN_WIDTH
#define NavH (StatusRectH + NavRectH)
#define TabH (kDevice_Is_iPhoneX?83.f:49.f)
#define TabbarHeight (kDevice_Is_iPhoneX?83.f:49.f)
#define TabSaveHeight (kDevice_Is_iPhoneX?34.f:0)
#define kDevice_Is_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
眼睛尖的肯定看到了我写了个非控制器专用的navi的高度,这个主要是应对那些你需要在项目中做弹出视图(单独拆分出来)的地方用到关于系统的高度,那个里面可没有navigation,但你还是要除掉他的高度,写个系统方法就好了
@implementation DRFunctionUnit
+ (UINavigationController *)getNavVC{
UIViewController * Rootvc = [[UIApplication sharedApplication] keyWindow].rootViewController;
UITabBarController * tabVC = (UITabBarController *)Rootvc;
UINavigationController *nav = (UINavigationController*)tabVC.selectedViewController;
return nav;
}
//scrollView相关iOS11适配
#define adjustsScrollViewInsets(scrollView)\
do {\
_Pragma("clang diagnostic push")\
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"")\
if ([scrollView respondsToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\
NSMethodSignature *signature = [UIScrollView instanceMethodSignatureForSelector:@selector(setContentInsetAdjustmentBehavior:)];\
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];\
NSInteger argument = 2;\
invocation.target = scrollView;\
invocation.selector = @selector(setContentInsetAdjustmentBehavior:);\
[invocation setArgument:&argument atIndex:2];\
[invocation retainArguments];\
[invocation invoke];\
}\
_Pragma("clang diagnostic pop")\
} while (0)