如果用户关闭 displayAlert,如何停止 imagecropper 插件中的 activity 指示器?

how to stop activity indicator in imagecropper plugin, if user closes displayAlert?

问题是 在步骤 #2 中,如果用户不选择选项或只是关闭 displayAlert 而不是 activityIndicator 运行永远。如果用户关闭了 displayAlert(在步骤#2 中),我知道如何停止 Activity Indicator 吗?

参考:imagecropper plugin

下面是您看到的完整代码流程:

  1. 在主页上 - 使用 activityIndicator
  2. 开始加载
  3. 打开 displayAlert,有 2 个选项:“上传图片”或“拍照”
  4. 打开相机
  5. 拍照
  6. 符合照片
  7. 转到主页并等待 2 秒(这很糟糕,但还可以)
  8. 打开裁剪图片编辑器
  9. 关闭裁剪图像编辑器并转到主页
  10. 使用 activityIndicator
  11. 停止加载

来自 link

的默认代码
      //run loading if user picked a option
      activityIndicator.IsRunning = true;

     //this code always get run last thing in method
        new ImageCropper()
        {
          Success = (imageFile) =>
          {
             Device.BeginInvokeOnMainThread(() =>
             {
               //turn off loading
               activityIndicator.IsRunning = false;
               imageView.Source = ImageSource.FromFile(imageFile);
              });
           }
         }.Show(this);

抱歉回复晚了,其实我想把这个放在评论里,但是评论里真的很难看懂。 我想你可以试试这个代码:

    new ImageCropper()
    {
      Success = (imageFile) =>
      {
         Device.BeginInvokeOnMainThread(() =>
         {
           //turn off loading
           activityIndicator.IsRunning = false;
           imageView.Source = ImageSource.FromFile(imageFile);
          });
       },
       //this 'faiure' is not typo, check ImageCropper.cs in your link
       Faiure = () =>
            {
                activityIndicator.IsRunning = false;
            }
     }.Show(this);