2

我有以下ViewController课程,我正在尝试显示实时照片。我不确定如何真正让图像显示在处理 UIImageView 时,我会写这样的东西:

let image = UIImage(imageNamed: "someStringPointingToImage") //then add this to the image view.

但是有谁知道它是如何与我添加到我的资产中的实时图像一起工作的?

功能

import UIKit
import Photos;
import PhotosUI
import MobileCoreServices

class ViewController: UIViewController, PHLivePhotoViewDelegate {

    var livePhotoIsAnimating = Bool()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.livePhotoView()
    }

    //MARK: Create the Live Photoview
    func livePhotoView() {

        let photoView: PHLivePhotoView = PHLivePhotoView.init(frame: self.view.bounds)
        //%%%%%%% Area to add the image %%%%%% 
        photoView.contentMode = .ScaleAspectFill

        self.view.addSubview(photoView)
        self.view.sendSubviewToBack(photoView)


    }


    func livePhotoView(livePhotoView: PHLivePhotoView, willBeginPlaybackWithStyle playbackStyle: PHLivePhotoViewPlaybackStyle) {


        self.livePhotoIsAnimating = true

    }

    func livePhotoView(livePhotoView: PHLivePhotoView, didEndPlaybackWithStyle playbackStyle: PHLivePhotoViewPlaybackStyle) {

        self.livePhotoIsAnimating = false

    }

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


}

谢谢。

4

1 回答 1

3

实时照片是照片应用程序的构造。唯一可以获得 Live Photo 的地方是 Photos 框架(反过来,它从用户的 Photos 库中获取)。无法将 Live Photos 作为捆绑资源存储在您的应用程序中。

如果要呈现动画图像,只需使用UIImage从一组帧创建动画图像的构造函数,并将它们显示在UIImageView. 添加您自己的手势识别器,您可以轻松创建一个默认呈现静态图像的 UI,以及在点击/按下/任何方式时呈现动画图像的 UI。

如果您想展示视频,请查看 AVKit。

于 2016-04-16T20:15:39.873 回答