UINavigationBar frame问题
有小伙伴反应,用navigationBar定义导航条,iOS11高度固定变为44.
UINavigationBar *bar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 375, 100)];
bar.backgroundColor = [UIColor greenColor];
[self.view addSubview:bar];
ios11以下:
iOS11上:
修复:
#import "ViewController.h"
@interface ViewController ()<UINavigationBarDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationBar *bar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 375, 64)];
bar.backgroundColor = [UIColor greenColor];
[self.view addSubview:bar];
bar.delegate = self;
bar.translatesAutoresizingMaskIntoConstraints = NO;
id guide = self.topLayoutGuide;
NSArray *constraintsA = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[bar]|" options:0 metrics:nil views:@{@"bar":bar}];
NSArray *constraintsC = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[guide][bar(==width)]" options:0 metrics:@{@"width":@44} views:NSDictionaryOfVariableBindings(guide,bar)];
[self.view addConstraints:constraintsC];
[self.view addConstraints:constraintsA];
}
- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
return UIBarPositionTopAttached;
}
@end
需要实现实现对应view的代理方法-tableView: viewForHeaderInSection:
否则高度的代理方法不会调用。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
return [UIView new];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.01;
}
或者实现
tableview.estimatedSectionHeaderHeight = 0 ;
tableview.estimatedSectionFooterHeight = 0 ;
图片、bundle文件等资源导入的问题(Xcode9的问题, 目前9.1版本已经修复)
默认没有勾选
需要勾选,或者手动添加到copy Bundle Resources
。
此外,蓝色目录也不会加进来,手动加加加
NSPhotoLibraryAddUsageDescription
我们知道iOS10访问相册,plist需要加NSPhotoLibraryUsageDescription
iOS11,添加图片到相册还需要加NSPhotoLibraryAddUsageDescription
,否则报错。
<key>NSPhotoLibraryUsageDescription</key>
<string>需要您的同意,才能访问相册</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>需要您的同意,才能保存图片到相册</string>
官方说明
列一下xcode8刚出时候的plist,来自http://www.jianshu.com/p/90d5323cf510:
<!-- 相册 -->
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<!-- 相机 -->
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>
<!-- 麦克风 -->
<key>NSMicrophoneUsageDescription</key>
<string>App需要您的同意,才能访问麦克风</string>
<!-- 位置 -->
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能访问位置</string>
<!-- 在使用期间访问位置 -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>App需要您的同意,才能在使用期间访问位置</string>
<!-- 始终访问位置 -->
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始终访问位置</string>
<!-- 日历 -->
<key>NSCalendarsUsageDescription</key>
<string>App需要您的同意,才能访问日历</string>
<!-- 提醒事项 -->
<key>NSRemindersUsageDescription</key>
<string>App需要您的同意,才能访问提醒事项</string>
<!-- 运动与健身 -->
<key>NSMotionUsageDescription</key>
<string>App需要您的同意,才能访问运动与健身</string>
<!-- 健康更新 -->
<key>NSHealthUpdateUsageDescription</key>
<string>App需要您的同意,才能访问健康更新 </string>
<!-- 健康分享 -->
<key>NSHealthShareUsageDescription</key>
<string>App需要您的同意,才能访问健康分享</string>
<!-- 蓝牙 -->
<key>NSBluetoothPeripheralUsageDescription</key>
<string>App需要您的同意,才能访问蓝牙</string>
<!-- 媒体资料库 -->
<key>NSAppleMusicUsageDescription</key>
<string>App需要您的同意,才能访问媒体资料库</string>
NFCReaderUsageDescription
请求NFC权限用:
<key>NFCReaderUsageDescription</key>
<string>我们要使用NFC了</string>
TitileView 和 UITabbarItem
可以参考:
http://www.matrixprojects.net/p/uibarbuttonitem-ios11/
iphoneX Push过程中TabBar向上偏移
解决方法参考:https://stackoverflow.com/questions/46232929/why-page-push-animation-tabbar-moving-up-in-the-iphone-x
- (void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated{
if (self.viewControllers.count != 0 ) {
if ([viewController isKindOfClass: NSClassFromString(@"QLPreviewController")]) {
}else{
viewController.navigationItem.leftBarButtonItem = [self c_BarButtonItem] ;
viewController.hidesBottomBarWhenPushed = true;
}
}
[super pushViewController:viewController animated:animated];
CGRect frame = self.tabBarController.tabBar.frame;
frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.size.height;
self.tabBarController.tabBar.frame = frame;
}