出现模态视图控制器时暂停动画

时间:2019-10-23 06:38:04

标签: ios swift lottie-ios

我有两个在主屏幕视图控制器上播放的动画。它们都是LottieFiles的动画。一个是背景变化的Alpha颜色,另一个是具有不同颜色的无限循环。选择当前上下文的新模态视图后,我想暂停两个动画,并在关闭模态视图后再次启动它们。我尝试调用animationView.pause方法,但是它们仍然继续在后台播放。我想暂停它们以提高能源效率。

      class HomeScreen: UIViewController{
 let animationView = AnimationView()
 let animationTwo = AnimationView()

 func showSupport() {

    let modalViewController = SupportViewController()
    modalViewController.modalPresentationStyle = .overCurrentContext
    present(modalViewController, animated: true, completion: nil)
}
 func showSInfo() {

    let modalViewController = InfoViewController()
    modalViewController.modalPresentationStyle = .overCurrentContext
    present(modalViewController, animated: true, completion: nil)
}
override func viewDidAppear(_ animated: Bool) {

    super.viewDidAppear(animated)


    animationView.play(fromProgress: 0,
                       toProgress: 1,
                       loopMode: LottieLoopMode.loop,
                       completion: { (finished) in
                        if finished {
                            print("Animation Complete")
                        } else {
                            print("Animation cancelled")
                        }
    })


    animationTwo.play(fromProgress: 0,
                       toProgress: 1,
                       loopMode: LottieLoopMode.loop,
                       completion: { (finished) in
                        if finished {
                            print("Animation Complete")
                        } else {
                            print("Animation cancelled")
                        }
    })

}
 override func viewDidLoad() {
   let animation = Animation.named("bg12")
    animationView.animation = animation
    animationView.contentMode = .scaleAspectFill
    view.addSubview(animationView)

    let animationViewTwo = Animation.named("infi2")
    animationTwo.animation = animationViewTwo
    animationTwo.contentMode = .scaleAspectFit
    animationTwo.alpha = 0.7
    view.addSubview(animationTwo)
 }
    }


 class SupportViewController: UIViewController {
     let homeVC = HomeScreen()

  override func viewDidLoad() {
    homeVC.animationView.pause()
    homeVC.animationTwo.pause()
    super.viewDidload()
}
 }

1 个答案:

答案 0 :(得分:0)

您不能将暂停放在现在的完成处理程序上,例如:

private void killExplorer()
{
  try
  {
     RegistryKey regKey = Registry.LocalMachine;

     regKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\", true);
     regKey.SetValue("AutoRestartShell", 0);


     var processes = Process.GetProcessesByName("explorer");
     Console.Write("Killing Explorer... ");
     foreach (var process in processes)
     {
        process.Kill();
        process.WaitForExit();
     }
     Console.WriteLine("Done");
  }
  catch(Exception ex)
  {
     log.Debug(ex);
     Console.WriteLine(ex);
  }
}