iOS 实用技术iOS精英班iOS菜鸟到大神

iOS 11 适配看这篇还不够?

2017-09-20  本文已影响1605人  Lefe

导航

iOS 11 中导航主要问题是,使自定义返回按钮点击区域变小了,导致用户体验很不好。主要有两种方法:

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80, 30)];
imageView.userInteractionEnabled = YES;
imageView.contentMode = UIViewContentModeLeft;
imageView.image = image;
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:imageView];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
imageView.userInteractionEnabled = YES;
imageView.contentMode = UIViewContentModeLeft;
imageView.image = image;
if ([imageView respondsToSelector:@selector(widthAnchor)]) {
    NSLayoutConstraint *widthConstraint = [imageView.widthAnchor constraintEqualToConstant:80];
    // Swift widthConstraint.isActive = YES;
    widthConstraint.active = YES;
}
    
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:imageView];

了解更多

automaticallyAdjustsScrollViewInsets 属性

iOS 11 后 UIViewController 的属性 automaticallyAdjustsScrollViewInsets,变为了 UIScrollView's contentInsetAdjustmentBehavior。如果发现界面无意中位置偏移了,很可能是这个属性导致的。


if (@available(iOS 11.0, *)) {
   self.collectionView.contentInsetAdjustmentBehavior =UIScrollViewContentInsetAdjustmentNever;
} else {
   self.automaticallyAdjustsScrollViewInsets = NO;
}

MJRefresh 出现的问题,看这个

applicationDidEnterBackground 不执行

APP 进入后台后,applicationDidEnterBackground: 这个方法将延迟大约 1000 毫秒执行, 那么如果在进入后台时做一些任务,可能会达不到预期的效果。如果 APP 刚进入应用立即启动,applicationDidEnterBackground: 和 applicationWillEnterForeground: 这两个方法都不会调用。如果有这么一个场景,进入后台后给应用设置手势密码,当 APP 刚进入后就立即启动,那么 applicationDidEnterBackground:这个方法不会立即执行,从而手势密码也就不会设置。

设备名称

如果你的项目中有有关设备名的显示,比如 来自 iPhone X,那么你需要适配下新设备:

@"iPhone10,1" : @"iPhone 8",
@"iPhone10,4" : @"iPhone 8",
@"iPhone10,2" : @"iPhone 8 Plus",
@"iPhone10,5" : @"iPhone 8 Plus",
@"iPhone10,3" : @"iPhone X",
@"iPhone10,6" : @"iPhone X",

当然这些值可以 看这里
推荐一个 第三方库

UIImagePickerController 设置导航背景图

[self.navigationBar setBackgroundImage:[UIImage imageNamed:@"navBg"] forBarMetrics:UIBarMetricsDefault];

这样设置发现对 UIImagePickerController 不起作用,需要使用:

self.navigationBar.barTintColor = [UIColor blackColor];

WebViewJavascriptBridge crash

如何你项目中使用 WebViewJavascriptBridge 与 H5 交互,那么这里有一个 crash。

解决方法

提交 AppStore

提交 AppStore 时需要 1024*1024 Logo,别好不容易打包好了,发现还需要一个 Logo,重新打包有点不值的。

appStore.png

iPhone X

statusbar.png
[UIApplication sharedApplication].statusBarFrame

{{0, 0}, {375, 44}}
LaunchScreen.png

如果不是采用 LaunchScreen.storyboard 这种方式作为启动页,可以 看这篇

更多

屏幕尺寸变化

参考

bugly

===== 我是有底线的 ======
喜欢我的文章,欢迎关注我的新浪微博 Lefe_x,我会不定期的分享一些开发技巧

上一篇 下一篇

猜你喜欢

热点阅读