Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CALayerを見直す

taminif
November 28, 2016

 CALayerを見直す

関西モバイルアプリ研究会 #20

taminif

November 28, 2016
Tweet

More Decks by taminif

Other Decks in Technology

Transcript

  1. CALayerΛܧঝͨ͠αϒΫϥε • CAEmitterLayer • CAGradientLayer • CAMetalLayer • CAEAGLLayer/ CAOpenGLLayer

    • CAReplicatorLayer • CAScrollLayer • CAShapeLayer • CATextLayer • CATiledLayer • CATransformLayer • QCCompositionLayer
  2. CALayerΛܧঝͨ͠αϒΫϥε • CAEmitterLayer • CAGradientLayer • CAMetalLayer • CAEAGLLayer/ CAOpenGLLayer

    • CAReplicatorLayer • CAScrollLayer • CAShapeLayer • CATextLayer • CATiledLayer • CATransformLayer • QCCompositionLayer
  3. CATextLayer override func viewDidLoad() { super.viewDidLoad() let textLayer = CATextLayer()

    textLayer.frame = textView.bounds let string = "Hello! Can I have a Tall Caramel Macchiato?" textLayer.string = string let fontName:CFString = "Noteworthy-Light" as CFString let fontSize:CGFloat = 14.0 textLayer.font = CTFontCreateWithName(fontName, fontSize, nil) textLayer.foregroundColor = UIColor.darkGray.cgColor textLayer.isWrapped = true textLayer.alignmentMode = kCAAlignmentLeft textLayer.contentsScale = UIScreen.main.scale textView.layer.addSublayer(textLayer) }
  4. AVPlayerLayer Class final class AVPlayerView : UIView { override public

    class var layerClass: Swift.AnyClass { get { return AVPlayerLayer.self } } fileprivate var playerLayer: AVPlayerLayer { return self.layer as! AVPlayerLayer } func player() -> AVPlayer { return playerLayer.player! } func setPlayer(_ player: AVPlayer) { playerLayer.player = player } func setVideoFillMode(_ fillMode: String) { playerLayer.videoGravity = fillMode } func videoFillMode() -> String { return playerLayer.videoGravity } }
  5. AVPlayerLayer Layer let path = Bundle.main.path(forResource: "cat", ofType: "mp4") let

    fileURL = URL(fileURLWithPath: path!) let avAsset = AVURLAsset(url: fileURL, options: nil) let playerItem = AVPlayerItem(asset: avAsset) let videoPlayer = AVPlayer(playerItem: playerItem) let layer = playerView.layer as! AVPlayerLayer layer.videoGravity = AVLayerVideoGravityResizeAspect layer.player = videoPlayer videoPlayer.play()
  6. αϯϓϧίʔυ let subLayer:CALayer = CALayer.init() subLayer.frame = image.bounds image.layer.addSublayer(subLayer) subLayer.masksToBounds

    = true let size:CGSize = subLayer.bounds.size var x:CGFloat = -10.0 var y:CGFloat = -10.0 let pathRef:CGMutablePath = CGMutablePath() pathRef.move(to: CGPoint(x: x, y: y)) x += size.width + 10.0 pathRef.addLine(to: CGPoint(x: x, y: y)) y += 10.0 pathRef.addLine(to: CGPoint(x: x, y: y)) x -= size.width pathRef.addLine(to: CGPoint(x: x, y: y)) y += size.height pathRef.addLine(to: CGPoint(x: x, y: y)) x -= 5.0 pathRef.addLine(to: CGPoint(x: x, y: y)) y -= size.height pathRef.addLine(to: CGPoint(x: x, y: y)) pathRef.closeSubpath() subLayer.shadowOffset = CGSize(width: 5, height: 5) subLayer.shadowColor = UIColor.black.cgColor subLayer.shadowOpacity = 0.5 subLayer.shadowPath = pathRef