KotlinとSwiftでアナログ時計を作るーー長針、短針、秒針の更新処理(後)

こんにちは。川上です。
Swift版アナログ時計作成している長針、短針、秒針の更新や関連処理の諸々。
Timerで使った一般的な(?)表示の更新。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |  // -- ライフサイクル:初期化メソッド     override func viewDidLoad() {         super.viewDidLoad()         ・・・         // ーーー Timerスケジュール --         timerGameFunc()     }   func timerGameFunc() {          Timer.scheduledTimer(timeInterval: 1.0,             target: self,             selector: #selector(ViewController.timerUpdate),             userInfo: nil,             repeats: true)     }     @objc func timerUpdate() {         // --- アナログ時計Timer時の各針表示更新         startTimeClock()     } | 
MyPrg内でアッチャコッチャで使っている諸々の処理の色々。
 ・日付Dateの取得処理
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | struct TotnDate {     // MARK: +++ add Weekday [ "日", "月", "火", "水", "木", "金", "土"];     // MARK: ++++ Dateから 年・月・日・時・分・秒 の各Intを取得     static func convertNSDateToYMDHMS (date: NSDate) -> (yy:Int,mth:Int,day:Int,hh:Int,min:Int,sec:Int,wkday:Int) {         let gcal = NSCalendar(identifier: NSCalendar.Identifier.gregorian)!         let flags : NSCalendar.Unit = [NSCalendar.Unit.year             ,NSCalendar.Unit.month             ,NSCalendar.Unit.day             ,NSCalendar.Unit.hour             ,NSCalendar.Unit.hour             ,NSCalendar.Unit.minute             ,NSCalendar.Unit.second             ,NSCalendar.Unit.nanosecond             ,NSCalendar.Unit.weekday]         let dComp = gcal.components(flags, from: date as Date)         let lYYY = dComp.year //as! Int         let lMM   = dComp.month //as! Int         let lDD   = dComp.day //as! Int         let lHH   = dComp.hour //as! Int         let lMINI   = dComp.minute //as! Int         let lSEC   = dComp.second //as! Int      // -- Weekday [ "日", "月", "火", "水", "木", "金", "土"]         let lWeekDay = dComp.weekday! - 1            return (yy:lYYY!,mth:lMM!,day:lDD!,hh:lHH!,min:lMINI!,sec:lSEC!,wkday:lWeekDay)     } } | 
> Date取得ログ:datetpl =(yy: 2019, mth: 7, day: 18, hh: 13, min: 17, sec: 22, wkday: 4)
・ImageViewのリサイズ。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | // --- UIImageのextension : extension UIImage {     // MARK:+++ リサイズ resize     func resize(size _size: CGSize) -> UIImage? {         let widthRatio = _size.width / size.width         let heightRatio = _size.height / size.height         let ratio = widthRatio < heightRatio ? widthRatio : heightRatio         let resizedSize = CGSize(width: size.width * ratio, height: size.height * ratio)         UIGraphicsBeginImageContextWithOptions(resizedSize, false, 0.0)          draw(in: CGRect(origin: .zero, size: resizedSize))         let resizedImage = UIGraphicsGetImageFromCurrentImageContext()         UIGraphicsEndImageContext()         return resizedImage     } } | 
現状、Swift4.2で使えますが、Swift5.0では、ワーニング潰しが要るかも・・です
iPhone用の動画はココです。
ではでは。

