繁体   English   中英

Xamarin中未显示ImagePicker

[英]ImagePicker Not Showing In Xamarin

我的应用程序中有一个图像选择器,可以打开用户相册(iOS),以便他们选择图像。 我正在使用xamarin跨平台,所以我有一个依赖服务导致了这段代码。 之后,我得到了所有正确的代码,但是问题是图像选择器没有显示前一两次,而是仅在用户刷新整个应用程序后才开始工作。 这是我用来创建选择器的以下代码:

        imagePicker = new UIImagePickerController ();
        imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
        imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.PhotoLibrary);
        imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia;
        imagePicker.Canceled += Handle_Canceled;
        //Show the picker
        UIApplication.SharedApplication.KeyWindow.RootViewController.PresentModalViewController (imagePicker, true);

请注意,我已经尝试过NavigationController.PresentModalViewController,但最终会出现null错误。 我也只尝试了“ PresentViewController”,但没有帮助。 此外,还有其他显示图片选择器的方法吗? 任何帮助将不胜感激!

而不是使用DependencyService,请尝试Xamarin Media插件。

var file = await CrossMedia.Current.PickPhotoAsync();

在6.0中不推荐使用PresentModalViewController https://developer.xamarin.com/api/member/UIKit.UIViewController.PresentModalViewController/p/UIKit.UIViewController/System.Boolean/

尝试更改此行:

UIApplication.SharedApplication.KeyWindow.RootViewController.PresentModalViewController (imagePicker, true);

对此:

UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController (imagePicker, true, null);

似乎您尚未设置ModalPresentationStyle属性。 我还注意到PresentModalViewController方法中缺少动作处理程序参数。

imagePicker.ModalPresentationStyle = UIModalPresentationStyle.Popover;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM