一、状态条获取,旧方法会闪退,修改如下:
if (@available(iOS 13.0, *)) {
UIWindow *keyWindow = [UIApplication sharedApplication].windows[0];
statusBar = [[UIView alloc]initWithFrame:keyWindow.windowScene.statusBarManager.statusBarFrame] ;
[keyWindow addSubview:statusBar];
} else {
statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
}
二、performSegueWithIdentifier跳转 UIViewController 不全屏,解决方法:
需要设置目的 UIViewController 的modalPresentationStyle为UIModalPresentationFullScreen
在源 UIViewController 加代码:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
UIViewController *vc = segue.destinationViewController;
vc.modalPresentationStyle = UIModalPresentationFullScreen;
}
三、拍照返回图片获取路径,之前的PHImageFileURLKey返回空了
解决方法:
1、writeImageToSavedPhotosAlbum方法保存UIImage到相册
2、从回调的assetURL 中取到图片 id
3、PHAsset的fetchAssetsWithLocalIdentifiers方法获取PHAsset
4、PHAsset的requestContentEditingInputWithOptions方法获取图片路径
代码如下:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *image = info[UIImagePickerControllerOriginalImage];
ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];
__weak typeof(self) weakSelf = self;
//保存图片
[lib writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
//获取图片 id
NSURLComponents *urlComponents = [[NSURLComponents alloc] initWithString:assetURL.absoluteString];
NSString *usePath = @"";
for(int i=0;i<urlComponents.queryItems.count;i++){
if ([urlComponents.queryItems[i].name isEqualToString:@"id"]){
usePath =urlComponents.queryItems[i].value;
break;
}
}
//根据图片 id 获取PHAsset
PHFetchResult * re = [PHAsset fetchAssetsWithLocalIdentifiers:@[usePath] options:nil];
[re enumerateObjectsUsingBlock:^(PHAsset * _Nonnull asset, NSUInteger idx, BOOL * _Nonnull stop) {
//根据PHAsset调用requestContentEditingInputWithOptions获取url
PHContentEditingInputRequestOptions *editOptions = [[PHContentEditingInputRequestOptions alloc] init];
[asset requestContentEditingInputWithOptions:editOptions completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
if (contentEditingInput.fullSizeImageURL) {
NSLog(@"Image path: %@", contentEditingInput.fullSizeImageURL);
}else{
NSLog(@"Error retrieving image filePath, heres whats available: %@", info);
}
}];
}];
}];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
网友评论