Skip to content

Instantly share code, notes, and snippets.

@yakimelon
Created July 14, 2018 09:10
Show Gist options
  • Save yakimelon/6f308d411f15be6ac1f7430e9effc36c to your computer and use it in GitHub Desktop.
Save yakimelon/6f308d411f15be6ac1f7430e9effc36c to your computer and use it in GitHub Desktop.
import AVFoundation
import UIKit
// レイヤーをAVPlayerLayerにする為のラッパークラス.
class AVPlayerView : UIView {
// UIViewのサブクラスを作りlayerClassメソッドをオーバーライドしてAVPlayerLayerに差し替える
override class var layerClass: AnyClass {
return AVPlayerLayer.self
}
// AVPlayerのgetterとsetter
var player: AVPlayer {
get {
let layer: AVPlayerLayer = self.layer as! AVPlayerLayer
return layer.player!
}
set(newValue) {
let layer: AVPlayerLayer = self.layer as! AVPlayerLayer
layer.player = newValue
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment