カテゴリー
iOS Swift

CMTimeについて

CMTime is a structure that represents time.

timescaleは1秒を何分割するか
valueはそのtimescale内でどの数値分進むか
例) value: 600, timescale: 600 の場合、600/600 で1秒を表す

カテゴリー
iOS Swift

UIView内でSwiftUIのViewを使用する

struct PlayController: View {
  var buttonSize:CGFloat = 32
  var body: some View {
    HStack(spacing: 30) {
      Button {
	
      } label: {
        Image(systemName: "stop.fill")
	  .resizable()
	  .frame(width: buttonSize, height: buttonSize)
      }
      Button {
				
      } label: {
        Image(systemName: "play.fill")
	  .resizable()
	  .frame(width: buttonSize, height: buttonSize)
      }
      Button {
			
      } label: {
        Image(systemName: "backward.end.fill")
	  .resizable()
	  .frame(width: buttonSize, height: buttonSize)
      }
      Button {
				
      } label: {
	Image(systemName: "forward.end.fill").resizable()
	  .resizable()
	  .frame(width: buttonSize, height: buttonSize)
      }
    }
  }
}
import UIKit
import SwiftUI

class ViewController: UIViewController {
	
  override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    view.backgroundColor = .red
    constrainControllers()
  }
	
  private func constrainControllers() {
    let controlSwiftUIView = PlayController()
    let controller = UIHostingController(rootView: controlSwiftUIView)
	    
    controller.view.translatesAutoresizingMaskIntoConstraints = false
      self.addChild(controller)
      self.view.addSubview(controller.view)
      controller.didMove(toParent: self)
      controller.view.heightAnchor.constraint(equalToConstant: 100).isActive = true
      controller.view.leadingAnchor.constraint(equalTo: self.view.layoutMarginsGuide.leadingAnchor).isActive = true
      controller.view.trailingAnchor.constraint(equalTo: self.view.layoutMarginsGuide.trailingAnchor).isActive = true
      controller.view.bottomAnchor.constraint(equalTo: self.view.layoutMarginsGuide.bottomAnchor).isActive = true
  }
}
カテゴリー
iOS Swift

Storyboardを使わずにViewをAutoLayoutする

let constraints = [
    view.centerXAnchor.constraint(equalTo: superview.centerXAnchor),
    view.centerYAnchor.constraint(equalTo: superview.centerYAnchor),
    view.widthAnchor.constraint(equalToConstant: 100),
    view.heightAnchor.constraint(equalTo: view.widthAnchor)
]
NSLayoutConstraint.activate(constraints)
extension UIView {

    /* Constraint creation conveniences. See NSLayoutAnchor.h for details.
     */
    open var leadingAnchor: NSLayoutXAxisAnchor { get }

    open var trailingAnchor: NSLayoutXAxisAnchor { get }

    open var leftAnchor: NSLayoutXAxisAnchor { get }

    open var rightAnchor: NSLayoutXAxisAnchor { get }

    open var topAnchor: NSLayoutYAxisAnchor { get }

    open var bottomAnchor: NSLayoutYAxisAnchor { get }

    open var widthAnchor: NSLayoutDimension { get }

    open var heightAnchor: NSLayoutDimension { get }

    open var centerXAnchor: NSLayoutXAxisAnchor { get }

    open var centerYAnchor: NSLayoutYAxisAnchor { get }

    open var firstBaselineAnchor: NSLayoutYAxisAnchor { get }

    open var lastBaselineAnchor: NSLayoutYAxisAnchor { get }
}