我的应用程序中有一个图像选择器,可以打开用户的相册(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,但最后出现了一个空错误。我也试过"PresentViewController“,但没有帮助。另外,有什么不同的方式显示图像选择器吗?任何帮助都将不胜感激!
发布于 2016-04-24 21:51:47
与其使用DependencyService,不如试试Xamarin培养基插件。
var file = await CrossMedia.Current.PickPhotoAsync();发布于 2016-04-24 21:51:20
PresentModalViewController在6.0 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);发布于 2016-04-24 21:51:58
看起来您还没有设置ModalPresentationStyle属性。我还注意到了PresentModalViewController方法中缺少的动作处理程序参数。
imagePicker.ModalPresentationStyle = UIModalPresentationStyle.Popover;https://stackoverflow.com/questions/36829194
复制相似问题