본문 바로가기

iOS

[iOS] Core Animation으로 햄버거 만들기(미완성)

//
//  ViewController.swift
//  CoreAniStudy
//
//  Created by LIMGAUI on 2022/06/25.
//

import UIKit

class ViewController: UIViewController {
  lazy var burgerView = BurgerView(frame: view.bounds)
  override func viewDidLoad() {
    super.viewDidLoad()
    
  }
}

class BurgerView: UIView {
  override func draw(_ rect: CGRect) {
    let bread = UIBezierPath(
      roundedRect:
        CGRect(
          x: bounds.width * 0.1,
          y: bounds.height * 0.8,
          width: bounds.width * 0.8,
          height: bounds.height * 0.1),
      cornerRadius: 5)
    bread.lineWidth = 5
    UIColor.systemBrown.set()
    bread.stroke()
    
    let pati = UIBezierPath()
    pati.lineWidth = 20
    pati.lineCapStyle = .round
    pati.move(to: CGPoint(x: bounds.width * 0.1, y: bounds.height * 0.7))
    pati.addLine(to: CGPoint(x: bounds.width * 0.9, y: bounds.height * 0.7))
    pati.stroke()
    
    let yangsangchu = UIBezierPath()
    UIColor.systemGreen.set()
    yangsangchu.lineWidth = 10
    yangsangchu.lineCapStyle = .round
    yangsangchu.move(to: CGPoint(x: bounds.width * 0.1, y: bounds.height * 0.6))

    var width: CGFloat = 0.2
    for i in 0...7 {
      if i % 2 == 0 {
          yangsangchu.addQuadCurve(to: CGPoint(x: bounds.width * width, y: bounds.height * 0.6),
                                   controlPoint: CGPoint(x: bounds.width * (width - 0.05), y: bounds.height * 0.65))
      } else {
          yangsangchu.addQuadCurve(to: CGPoint(x: bounds.width * width, y: bounds.height * 0.6),
                                   controlPoint: CGPoint(x: bounds.width * (width - 0.05), y: bounds.height * 0.55))
      }
      width += 0.1
    }
    yangsangchu.stroke()
    
    let tomato = UIBezierPath()
    UIColor.systemRed.set()
    tomato.lineWidth = 15
    tomato.move(to: CGPoint(x: bounds.width * 0.1, y: bounds.height * 0.5))
    tomato.addLine(to: CGPoint(x: bounds.width * 0.45, y: bounds.height * 0.5))
    
    tomato.move(to: CGPoint(x: bounds.width * 0.55, y: bounds.height * 0.5))
    tomato.addLine(to: CGPoint(x: bounds.width * 0.9, y: bounds.height * 0.5))
    tomato.stroke()
    
    let sauce = UIBezierPath()
    sauce.lineWidth = 3
    UIColor.systemOrange.set()
    sauce.move(to: CGPoint(x: <#T##Int#>, y: <#T##Int#>))
    sauce.stroke()
  }
}