본문 바로가기

프로그래밍/iOS,macOS

(64)
[Metal] AR 얼굴인식 및 obj 렌더링 AR 환경에서 얼굴의 anchor 에 obj 파일을 렌더링 하는 내용을 다룬다. 다른 환경으로의 전달을 위해 별도의 렌더타겟을 만들고, CVPixelBuffer로 복사하는 방식 사용하며, 실제 뷰 렌더링은 다루지 않는다. 공유타입 #include typedef struct { matrix_float4x4 projectionMatrix; matrix_float4x4 viewMatrix; matrix_float4x4 modelMatrix; matrix_float3x3 normalMatrix; vector_float3 ambientLightColor; vector_float3 directionalLightDirection; vector_float3 directionalLightColor; float mater..
[Metal] Render to Texture 버텍스 let vertexData:[Float] = [ -1.0, -1.0, 0.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, ] 버퍼 let size = vertexData.count * MemoryLayout.size // var vertexBuffer:MTLBuffer vertexBuffer = device.makeBuffer(bytes: vertexData, length: size) vertexBuffer.label = "VertexBuffer" 렌더타겟용 텍스처 생성 렌더링에 사용할 텍스처는 MTKTextureLoader 등으로 별로 생성 let texDescriptor = MTLTextureDescriptor() t..
UIButton selected + highlighted image 버튼에 selected 상태의 이미지가 별도로 있는 경우 highlighted 이미지를 selected 이미지로 설정하기 override var isSelected: Bool { didSet { if isSelected { if let img = self.image(for: .selected) { self.setImage(img, for: UIControl.State.selected.union(.highlighted)) } } } }
CaptureSession 카메라, 마이크 var captureSession: AVCaptureSession! var videoPreviewLayer: AVCaptureVideoPreviewLayer! viewDidLoad 퍼미션 체크, 요청 switch AVCaptureDevice.authorizationStatus(for: .video) { case .notDetermined: break case .restricted: break case .denied: if let url = URL(string: UIApplication.openSettingsURLString) { if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHa..
Codable for Dictionary extension Encodable { func getValue() throws -> [String:Any] { let data = try JSONEncoder().encode(self) if let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String:Any] { return dictionary } throw NSError() } } extension Decodable { func setValue(from: [String:Any] ) throws { let data = try JSONSerialization.data(withJSONObject: from, options: .prettyP..
UITableView , UICollectionView 테이블뷰 UITableViewController 테이블뷰의 특정 기능에 대한 지원이 추가된 UIViewController 테이블뷰가 이미 생성되어 있음 정적 테이블 구성으로 스토리보드나 IB에서 디자인이 수월하나 변경에 제약이 많음 커스텀이 필요한경우 UIViewController에 UITableView을 추가해 사용 주요클래스 UITableView UITableViewCell UITableViewDelegate UITableViewDataSource cell class IB에서 클래스를 지정하고, Identity 를 지정한다. 해당 id는 datasource구현시 재사용큐에서 cell을 얻어올때 사용한다. class CustomCell : UITableViewCell { } 컨트롤러 class Test..
[iOS] 키보드를 따라 올라오는 뷰 해당 뷰의 bottom contraint 를 키보드 사이즈에 맞춰 변경(auto layout 을 사용하지 않는 경우 해당 뷰 프레임을 직접 변경) @IBOutlet weak var editView: NSLayoutConstraint! 키보드 이벤트 등록 NotificationCenter.default.addObserver( self, selector: #selector(MyViewController.keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) NotificationCenter.default.addObserver( self, selector: #selector(MyViewController.keyboardWi..
[iOS] Google SignIn pod 'Firebase/Auth' pod 'GoogleSignIn' import GoogleSignIn import FirebaseAuth AppDelegate.swift class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate { } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { FirebaseApp.configuration() GIDSignIn.sharedInstance().clientID = "클라이언트ID" . . re..