从手机发送UIAnimation以观看Swift WatchKit

时间:2018-11-10 00:32:11

标签: ios swift animation watchkit

今天,我有一个问题,那就是在伴随的iOS应用上生成动画后,将由png图像数组组成的动画图像(UIAnimation发送到Apple Watch。

我正在使用Swift构建应用程序,并能够在手机屏幕上的图像视图插座中成功生成动画。现在,我试图在Apple Watch上显示创建的动画。

import UIKit

class ViewController: UIViewController {

var images: [UIImage]!
var progressionAnimation: [UIImage]!

var loading_1: UIImage!
var loading_2: UIImage!
var loading_3: UIImage!

@IBOutlet weak var progressionAnimation: UIImageView!


override func viewDidLoad() {

    loading_1 = UIImage(named: "B")
    loading_2 = UIImage(named: "C")
    loading_3 = UIImage(named: "D")


    images = [loading_1, loading_2, loading_3]


    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


@IBAction func animationSelectionPressed(_ sender: Any) {
    progressionAnimation.animationImages = images
    progressionAnimation.startAnimating()
}



    @IBAction func startStopButtonPressed(_ sender: UIButton) {

    if progressionAnimation.isAnimating{
        progressionAnimation.stopAnimating()

    }
    else {
        progressionAnimation.startAnimating()
    }

}

@IBAction func animationSpeedSlow(_ sender: Any) {

    progressionAnimation.animationDuration = 1.0
    progressionAnimation.startAnimating()

}

@IBAction func animationSpeedFast(_ sender: Any) {

    progressionAnimation.animationDuration = 5.0
    progressionAnimation.startAnimating()

}

我已将WatchConnectivity框架添加到iOS应用程序,设置了捆绑标识符以匹配,并能够在模拟器上成功运行该应用程序。但是,我现在的问题是,当尝试在手表上显示动画时,我不想让该代码重复并使用存储在手表上的图像创建动画,而我基本上希望手表仅显示正在播放的实时动画。在手机上播放时,因此手机主要充当控制器。

任何见识都会受到赞赏和帮助。

0 个答案:

没有答案