AppDelegateに一番下のメニューを追加しました。
- (void)addBottomMenu
{
BottomMenu *bottomMenu = [[BottomMenu alloc] initWithFrame:CGRectMake(0, [ScreenHelper getHeightOfScreen] - 70, 320, 70)];
bottomMenu.delegate = self;
[[[[UIApplication sharedApplication] delegate] window] addSubview:bottomMenu];
}
メニューには、ギャラリーから写真を撮るためのボタンとカメラで写真を撮るためのボタンが2つあります。このボタンをグローバルに同じように機能させたい(すべてのコントローラーで)。ギャラリー(またはカメラ)が表示され、ユーザーが写真を選択(または撮影)した後、同じコントローラーに移動して画像を表示するように機能するはずです。コントローラに次のコード行を追加します。
- (void)photoButtonTapped
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
#pragma mark Image Picker delegates
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
imageOfReceipt = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:@"detailReceiptSegue" sender:self];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
... photoButtonTappedはデリゲートからのものです。それは機能しています(AppDelegateに追加したときではなく、コントローラーでボトムメニューを試していたとき)。AppDelegateでは、View Controllerの表示に問題があります(理由はわかりますが、これをバイパスする方法がわかりません)。AppDelegateで機能させる必要があります。これをすべてのコントローラーに複製して、AppDelegateのBottomMenuのデリゲートを変更したくありません。グローバルにそれを行うことは可能ですか?
はい、そうです。電話しない理由:
[self.navigationController.topViewController presentViewController:picker
animated:YES
completion:NULL];
AppDelegateにnavigationControllerプロパティがない場合は、現在表示されているViewControllerを別の方法で取得してみてください。たとえば、self.window.rootViewControllerを試してください。そして、おそらくセグエの使用をやめるべきです。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加