我正在创建自己的 iMessage 自定义应用程序,我只是想发送一个在 2 个图像之间交换背景的 iMessage,从而产生动画的错觉。我什至不确定这是可能的,但我正在尝试使用下面的代码。此代码仅在收件人收到邮件时显示第一张图片。任何帮助,将不胜感激。
func createImageForMessage() -> UIImage? {
let cupAnimation = UIImageView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
let imagesListArray = [UIImage(named: "boy_cup_1_1.png")!,UIImage(named: "boy_cup_1_7.png")!]
cupAnimation.animationImages = imagesListArray
cupAnimation.animationDuration = 10.0
cupAnimation.animationRepeatCount = 50
cupAnimation.startAnimating()
let cupBackground = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
cupBackground.addSubview(cupAnimation)
background.addSubview(cupBackground)
background.frame.origin = CGPoint(x: view.frame.size.width, y: view.frame.size.height)
view.addSubview(background)
UIGraphicsBeginImageContextWithOptions(background.frame.size, false, UIScreen.main.scale)
background.drawHierarchy(in: background.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
background.removeFromSuperview()
return image
}