【发布时间】:2021-02-12 09:52:00
【问题描述】:
我遇到了一个问题,当点击缩略图时,此操作有效。
-(IBAction)thumbnailTapped:(UIGestureRecognizer *)tap
{
if (_customItem.file.isEmpty)
{
[self openCamera]; // opens camera if no image is present
}
else
{
_isTransitioningToFullViewOrCamera = true;
[self performSegueWithIdentifier:@"CustomFileViewFromItem" sender:self]; // if file is present then it shows the picture blown up.
}
}
并调用以下代码:
-(void) openCamera
{
_isTransitioningToFullViewOrCamera = true;
NSString *ext = _customItem.file ? _customItem.file.ext : JpgExt;
if ([CustomCameraController isCameraAvailableForExt:ext forViewController:self])
[CustomCameraController launchCameraForExt:ext forViewController:self];
}
但是当从 UIAlertAction 调用时,相机根本不会打开。
UIAlertController *actionSheet;
actionSheet = [UIAlertController alertControllerWithTitle:@"Select an action:" message:nil preferredStyle:UIAlertControllerStyleAlert];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
// Cancel button tappped.
[self dismissViewControllerAnimated:YES completion:^{
}];
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Replace" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
self dismissViewControllerAnimated:YES completion:^{
}];
[self openCamera];
}]];
// Present action sheet.
[self presentViewController:actionSheet animated:YES completion:nil];
如果[self openCamera] 是否放置在完成块中,它不会改变任何东西。
我想知道是否有人对此有任何经验;当 UIAlertController 不存在(例如单击)时,[self openCamera] 打开相机,您可以拍照;但是,当在 UIAlertController 出现后调用时,相机将不会打开并静默失败。
【问题讨论】:
标签: ios objective-c iphone ios12