Skip to content

Instantly share code, notes, and snippets.

@woodycatliu
woodycatliu / class B: UIView
Created September 21, 2020 03:28
Swift - UIKit :繪製圓角Border
override func draw(_ rect: CGRect) {
borderColor.setStroke()
borderColor.withAlphaComponent(backgroundOpacity).setFill()
let backgroundPath = UIBezierPath(roundedRect: bounds, cornerRadius: borderCornerRadius)
backgroundPath.fill()
let borderPath: UIBezierPath
let borderRect = bounds.insetBy(dx: borderWidth / 2, dy: borderWidth / 2)
if borderCornerSize == 0 {
borderPath = UIBezierPath(roundedRect: borderRect, cornerRadius: borderCornerRadius)
} else {
{
"timeZone": "Asia/Hong_Kong",
"dependencies": {
},
"webapp": {
"access": "ANYONE_ANONYMOUS",
"executeAs": "USER_DEPLOYING"
},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": ["https://www.googleapis.com/auth/script.send_mail", "https://www.googleapis.com/auth/script.external_request", "https://www.googleapis.com/auth/script.scriptapp", "https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/userinfo.email"],
//
// ViewController.swift
// Created by Woody on 2021/1/28.
/*
a simple example for removing the superimposed ViewController behind
*/
import UIKit
@woodycatliu
woodycatliu / Back Camera VS. Device Orientation.swift
Last active January 28, 2021 01:47
Swift AVFoundation Orientation
func deviceExifOrientationForBackCamera(_ deviceOrientation: UIDeviceOrientation = UIDevice.current.orientation) -> CGImagePropertyOrientation{
switch deviceOrientation {
case .portrait:
return .right
case .landscapeLeft:
return .up
case .landscapeRight:
return .down
default:
return .right

跳轉頁面那件小事

前幾天PM 提出一個需求,需求是A頁面點擊 Button A 會跳轉到 B 頁面, 而 B頁面有一個 Button B 點擊後會重新推出一個新的 A頁面。 所以依照這需求邏輯,當用戶不停的反覆 butoon A -> button B ,ViewController 會無限疊上去。 雖然最後了解這問題是故意設計的,不用處理,但是我還是稍微測試一下。

####測試

方案一、

Firebase-ML Kit

近期收到PM通知,發票 QRCode 有時候會掃不到,同一張發票Android掃得到,但是公司另一個專案的 iOS 版的可以掃 。 這問題可大可小,經過幾次試驗以後,掃不到的那張發票用 Swift metaDataOutput 回傳的都是 nil, 上網查也查不出原因,有看到swift 開發者上有人發問,也不了了之。

為此特地請PM去問出另一個專案用的是 Firebase ML Kit.............

  • 結論
/*
更改 navigationBar 字體顏色
方法很多種,
只特別記錄一種萬用的
*/
func setNavigationBar() {
// 完全全黑
/*
Change UIAlert message textColor
*/
extension UIAlertAction {
var titleTextColor: UIColor? {
get {
return self.value(forKey: "titleTextColor") as? UIColor
} set {
@woodycatliu
woodycatliu / imageOrientation.swift
Created March 29, 2021 03:41
在處理相機圖片時(影片),需要先確定鏡頭方向,才能正確做ML分析,或是繪圖。以下分別列出iOS原生鏡頭跟UIImage orientation 跟 Firebase ML Kit 的轉換方法
// return UIImage.Orientation
private func imageOrientation(deviceOrientation: UIDeviceOrientation = UIDevice.current.orientation,
cameraPosition: AVCaptureDevice.Position = .front) -> UIImage.Orientation {
var deviceOrientation = deviceOrientation
if deviceOrientation == .faceDown || deviceOrientation == .faceUp || deviceOrientation == .unknown {
deviceOrientation = currectDeviceOrientation()
}
/*
關閉UIView Anitmate小技巧。
有時候設定一系列 View 互動動畫, 突然遇到一個需求,需要關閉特定動畫,但是其他動畫要繼續執行的需求時,
就會特別頭痛。
比如內建 TableView delete/ insert 動畫 + 自定義的其他動畫時,處理起來會特別煩瑣。
而我們可以用簡單的 UIView.performWithoutAnimation 配上 main Therad 處理這件事情
*/
UIView.performWithoutAnimation {
// 動畫被取消,但是自動判斷Difference 不會失效