【问题标题】:How to manage UIActivityViewController completion?如何管理 UIActivityViewController 完成?
【发布时间】:2018-05-16 08:38:34
【问题描述】:

要分享图像,我将其滑出屏幕。

现在发生的事情是:

  • 我刷图
  • 它展示了 UIActivityViewController
  • 我选择一个活动
  • 活动以模态方式显示

如果我取消活动:

  • 图像在屏幕上(视图已加载)
  • 图像移回

我需要什么:

  • 我取消活动
  • 图像不在屏幕上
  • 图像移回

我该怎么做?

这是我的代码:

        let activityViewController = UIActivityViewController(activityItems: [imageToShare], applicationActivities: nil)
    self.present(activityViewController, animated: true, completion: {
        print("presented")
        //self.grids.center = self.offScreenPosition
        print("position share is \(self.grids.center)")
    })

    switch deviceOrientation {
    case "portrait":
        activityViewController.completionWithItemsHandler = {(UIActivityType: UIActivityType?, completed: Bool, returnedItems: [Any]?, error: Error?) in
            if !completed {
                print("cancelled")
                self.moveViewVertically(.backIn, range: self.verticalRange)
            }
            if completed {
                print("completed")
                self.moveViewVertically(.backIn, range: self.verticalRange)
            }
        }
    case "landscape":
        activityViewController.completionWithItemsHandler = {(UIActivityType: UIActivityType?, completed: Bool, returnedItems: [Any]?, error: Error?) in
            if !completed {
                print("cancelled")
                self.moveViewHorizontally(.backIn, range: self.horizontalRange)
            }
            if completed {
                self.moveViewHorizontally(.backIn, range: self.horizontalRange)
            }
        }
    default:
        break
    }

打印出来看看发生了什么。 这是我的第一个应用程序。 谢谢你的帮助。

【问题讨论】:

    标签: ios swift xcode animation uiactivityviewcontroller


    【解决方案1】:

    您希望视图在 activityViewController 关闭之前移回吗?你可以试试这个:自定义一个 UIActivity 的子类,然后

    - (void)performActivity {
        // move your view back in
        [self activityDidFinish:YES];
    }
    

    【讨论】:

    • 否:我需要在活动后或取消后将视图移回。现在的问题:视图已经存在(它确实加载了),然后动画出现。在视图加载之前我需要动画。
    • 但是activityViewController.completionWithItemsHandler在动画完成后调用,你确定在动画前调用“print("cancelled")"还是"print("completed")"?
    • 是的,在图像移回之前取消并完成两次打印。
    【解决方案2】:

    问题解决了。 在moveView 方法中,我写了center.y -= 1 来移动视图。即在所需范围内的迭代。

    现在我做:

    UIView.animate(withDuration: 0.5) {
                self.grids.transform = CGAffineTransform(translationX: 0, y: -self.view.frame.height)}
    

    它按预期工作。

    【讨论】:

      猜你喜欢
      • 2012-09-15
      • 1970-01-01
      • 2014-02-24
      • 2021-01-26
      • 2015-03-25
      • 2012-07-11
      • 2020-07-24
      • 1970-01-01
      相关资源
      最近更新 更多