Skip to content

Instantly share code, notes, and snippets.

View tsuzukihashi's full-sized avatar
🎮

Ryo Tsuzukihashi tsuzukihashi

🎮
View GitHub Profile
@tsuzukihashi
tsuzukihashi / .gitignore
Created June 30, 2023 14:41
Swift, Xcode .gitignore
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
.DS_Store
UserInterfaceState.xcuserstate
GoogleService-Info.plist
## User settings
xcuserdata/
@tsuzukihashi
tsuzukihashi / BannerView.swift
Last active June 14, 2023 12:41
SwiftUI Admob Banner
import SwiftUI
import GoogleMobileAds
enum BannerType {
case main
var id: String {
switch self {
case .main:
return ""
@tsuzukihashi
tsuzukihashi / toCMSampleBuffer.swift
Last active November 27, 2023 00:13
UIView to CMSampleBuffer (UIViewをCMSampleBufferに変換するExtension)
import UIKit
import CoreMedia
extension UIView {
func toCMSampleBuffer() -> CMSampleBuffer? {
let scale: CGFloat = UIScreen.main.scale
let size: CGSize = .init(width: bounds.width * scale, height: bounds.height * scale)
guard let pixelBuffer = makeCVPicelBuffer(scale: scale, size: size) else { return nil }
defer {
CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags(rawValue: 0))
@tsuzukihashi
tsuzukihashi / DataExtension.swift
Last active July 7, 2023 09:42
Data → CMBlockBuffer → CMSampleBuffer
import AVKit
import AVFoundation
extension Data {
func toCMBlockBuffer() throws -> CMBlockBuffer {
var blockBuffer: CMBlockBuffer?
let data: NSMutableData = .init(data: self)
var source: CMBlockBufferCustomBlockSource = .init()
source.refCon = Unmanaged.passRetained(data).toOpaque()
@tsuzukihashi
tsuzukihashi / UIViewExtension.swift
Created December 8, 2021 01:30
UIViewをUIImageに変換するExtension
import UIKit
extension UIView {
var uiImage: UIImage {
let imageRenderer = UIGraphicsImageRenderer.init(size: bounds.size)
return imageRenderer.image { context in
layer.render(in: context.cgContext)
}
}
}
@tsuzukihashi
tsuzukihashi / TestPage.swift
Created December 1, 2019 11:37
SwiftUI ActivityViewController Share Image
import SwiftUI
struct TestPage: View {
@State private var rect: CGRect = .zero
@State private var uiImage: UIImage? = nil
@State private var showShareSheet = false
var body: some View {
VStack {
HStack {
@tsuzukihashi
tsuzukihashi / TestPage.swift
Created December 1, 2019 06:21
SwiftUI View to UIImage
import SwiftUI
struct TestPage: View {
@State private var rect: CGRect = .zero
@State var uiImage: UIImage? = nil
var body: some View {
VStack {
HStack {
Image(systemName: "sun.haze")
@tsuzukihashi
tsuzukihashi / Member.java
Created April 20, 2019 03:54
IDとNameを持ったメンバークラス
public class Member {
private int id;
private String name;
public Member(int id, String name){
this.id = id;
this.name = name;
}
public Member(){
@tsuzukihashi
tsuzukihashi / DDManager.cs
Last active August 31, 2019 06:57
Unity 全シーン管理マネージャーの作成 ref: https://qiita.com/tsuzukihashi/items/1d8a9fce4465c688c78a
using UnityEngine;
public class DDManager : MonoBehaviour {
public GameObject gameObject;
void Start () {
DontDestroyOnLoad(gameObject);
}
@tsuzukihashi
tsuzukihashi / file0.txt
Last active March 25, 2020 05:06
Unity uGUIをドラッグで動かしてステージを選ぶ ref: https://qiita.com/tsuzuki817/items/659a20ff57c83a022560
using UnityEngine;
using UnityEngine.EventSystems;
public class SlideController : MonoBehaviour, IDragHandler {
public RectTransform m_rectTransform = null;
public void OnDrag(PointerEventData eventData)
{
m_rectTransform.position += new Vector3(eventData.delta.x*0.01f, 0f, 0f);