Skip to content

Instantly share code, notes, and snippets.

View ktanaka117's full-sized avatar

Tanaka Kenji ktanaka117

View GitHub Profile
let textColorAnimation = CABasicAnimation(keyPath: "foregroundColor")
textColorAnimation.duration = 2.0 / 3 // duration = 30fpsのうちの約20frame
textColorAnimation.fromValue = Color.primaryBrand.cgColor
textColorAnimation.toValue = Color.black.cgColor
textColorAnimation.fillMode = .forwards
UIView.animate(withDuration: 2.0 / 3, animations: { [weak self] in
guard let strongSelf = self else { return }
strongSelf.animationText.add(textColorAnimation, forKey: "TextColor")
})
let transformTrans = CGAffineTransform(translationX: 0, y: -animationViewCenterMovementAmount)
let transformScale = CGAffineTransform(scaleX: 0.8, y: 0.8)
animationView.transform = transformTrans.concatenating(transformScale)
let transformTrans = CGAffineTransform(translationX: 0, y: -animationViewCenterMovementAmount)
let transformScale = CGAffineTransform(scaleX: 0.8, y: 0.8)
animationView.transform = transformScale.concatenating(transformTrans)
view.layoutIfNeeded()
animationView.play { [weak self] _ in
UIView.animate(withDuration: 1.0, animations: { [weak self] in
self?.widthConstraint.constant = 300
self?.heightConstraint.constant = 300
self?.view.layoutIfNeeded()
})
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {}
// ここでは Boat_Loader.json というバンドルされたアニメーションファイルを設定
let boatAnimation = LOTAnimationView(name: "Boat_Loader")
boatAnimation.contentMode = .scaleAspectFill
boatAnimation.frame = view.bounds
view.addSubview(boatAnimation)
boatAnimation.play()
@ktanaka117
ktanaka117 / weak.swift
Created September 28, 2018 09:42
よそから参照されていない、weak参照のプロパティは即座に解放されるという話。
import UIKit
class ViewController: UIViewController {
var presenter: Presenter!
func inject(presenter: Presenter) {
self.presenter = presenter
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
@ktanaka117
ktanaka117 / IUOChange.swift
Last active September 25, 2018 11:26
Swift 4.2におけるIUOの変更
// まとめ
// ①ImplicitlyUnwrappedOptional<T>で宣言された変数に、Tに "as!" でダウンキャストした変数を代入しようとすると、「それはnilにはならない(はず)」と警告が出る
// ②IUOで宣言した変数にはnilが入ることを前提とした上で、利用側でnilが入らない挙動を期待する場合は!をつけるように要求する変更
// ①
class ViewController {}
class PageViewController: ViewController {}
import XCTest
import KeychainAccess
@testable import AwesomeIOSDC
class AuthDataStoreTests: XCTestCase {
private let testAccessToken = "TestAccessToken"
private let accessTokenKey = "AccessToken"
private let keychain = Keychain(service: "TestService")
func testSaveAccessToken() {
import XCTest
import KeychainAccess
@testable import AwesomeIOSDC
class AuthDataStoreTests: XCTestCase {
let keychain = Keychain(service: Bundle.main.bundleIdentifier!) // ②
func testSaveAccessToken() {
let authDataStore = AuthDataStore() // ①
authDataStore.save(accessToken: "Congrats iOSDC "2018🎉") // ③, ④, ⑦