From b48eac28a9a920e9ed1a3b196fc4d6e2eb46ac45 Mon Sep 17 00:00:00 2001 From: keisukeYamagishi Date: Fri, 5 Jan 2024 11:49:58 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Change=20the=20animation=20from=20a=20fade-?= =?UTF-8?q?out=20to=20a=20flash=F0=9F=98=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tetris.xcodeproj/project.pbxproj | 12 ++++++++++ Tetris/Extention/UIView+.swift | 10 ++++----- Tetris/Model/Component/Bars.swift | 2 +- Tetris/View/Animate/Animation.swift | 34 +++++++++++++++++++++++++++++ Tetris/View/View/FieldView.swift | 7 +++--- 5 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 Tetris/View/Animate/Animation.swift diff --git a/Tetris.xcodeproj/project.pbxproj b/Tetris.xcodeproj/project.pbxproj index 96597fe..953a5e3 100644 --- a/Tetris.xcodeproj/project.pbxproj +++ b/Tetris.xcodeproj/project.pbxproj @@ -30,6 +30,7 @@ 9095E5B22A4291D900BD97F1 /* TetrisUnitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9095E5B12A4291D900BD97F1 /* TetrisUnitTest.swift */; }; 9095E5B92A4297CA00BD97F1 /* TetrisBarTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9095E5B82A4297CA00BD97F1 /* TetrisBarTest.swift */; }; 9097CC952B37C1970076784A /* acknowtt.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9097CC942B37C1970076784A /* acknowtt.ttf */; }; + 909E58732B47A46D00AD8805 /* Animation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 909E58722B47A46D00AD8805 /* Animation.swift */; }; 90AA74382B3EF85100304F8A /* Asset.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 90AA74372B3EF85100304F8A /* Asset.xcassets */; }; C791D7D81FE6205E00983F80 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0B335691F0E517100A8F6DF /* AppDelegate.swift */; }; F0B335741F0E517200A8F6DF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F0B335721F0E517200A8F6DF /* LaunchScreen.storyboard */; }; @@ -83,6 +84,7 @@ 9095E5B12A4291D900BD97F1 /* TetrisUnitTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TetrisUnitTest.swift; sourceTree = ""; }; 9095E5B82A4297CA00BD97F1 /* TetrisBarTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TetrisBarTest.swift; sourceTree = ""; }; 9097CC942B37C1970076784A /* acknowtt.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = acknowtt.ttf; sourceTree = ""; }; + 909E58722B47A46D00AD8805 /* Animation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animation.swift; sourceTree = ""; }; 90AA74372B3EF85100304F8A /* Asset.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Asset.xcassets; sourceTree = ""; }; F0B335661F0E517100A8F6DF /* Tetris.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tetris.app; sourceTree = BUILT_PRODUCTS_DIR; }; F0B335691F0E517100A8F6DF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -161,6 +163,7 @@ 900064742A447513008B7CF9 /* View */ = { isa = PBXGroup; children = ( + 909E58712B47A45F00AD8805 /* Animate */, 900064772A447513008B7CF9 /* View */, 9000647B2A447513008B7CF9 /* ViewController */, ); @@ -215,6 +218,14 @@ path = TetrisUnitTest; sourceTree = ""; }; + 909E58712B47A45F00AD8805 /* Animate */ = { + isa = PBXGroup; + children = ( + 909E58722B47A46D00AD8805 /* Animation.swift */, + ); + path = Animate; + sourceTree = ""; + }; F0B3355D1F0E517000A8F6DF = { isa = PBXGroup; children = ( @@ -378,6 +389,7 @@ 900064732A44750B008B7CF9 /* Cp.swift in Sources */, 900064812A447513008B7CF9 /* FieldView.swift in Sources */, 900064802A447513008B7CF9 /* Bar.swift in Sources */, + 909E58732B47A46D00AD8805 /* Animation.swift in Sources */, 9000646B2A44750A008B7CF9 /* Level.swift in Sources */, C791D7D81FE6205E00983F80 /* AppDelegate.swift in Sources */, 900064702A44750B008B7CF9 /* Bs.swift in Sources */, diff --git a/Tetris/Extention/UIView+.swift b/Tetris/Extention/UIView+.swift index 6dd4190..8990ff6 100644 --- a/Tetris/Extention/UIView+.swift +++ b/Tetris/Extention/UIView+.swift @@ -18,10 +18,10 @@ extension UIView { UIView.animate(withDuration: 1.0, delay: 1.0, animations: { [self] in - alpha = 0.0 - }, completion: { [self] _ in - alpha = 1.0 - completion() - }) + alpha = 0.0 + }, completion: { [self] _ in + alpha = 1.0 + completion() + }) } } diff --git a/Tetris/Model/Component/Bars.swift b/Tetris/Model/Component/Bars.swift index 97ca7bb..6601f31 100644 --- a/Tetris/Model/Component/Bars.swift +++ b/Tetris/Model/Component/Bars.swift @@ -178,7 +178,7 @@ final class Bars { } } } - + var isBottom: Bool { for tate in 0 ..< values.count { for yoko in 0 ..< values[tate].count { diff --git a/Tetris/View/Animate/Animation.swift b/Tetris/View/Animate/Animation.swift new file mode 100644 index 0000000..043e9cf --- /dev/null +++ b/Tetris/View/Animate/Animation.swift @@ -0,0 +1,34 @@ +// +// Animation.swift +// Tetris +// +// Created by keisuke yamagishi on 2024/01/05. +// Copyright © 2024 shichimitoucarashi. All rights reserved. +// + +import UIKit + +final class Animation { + var count = 0 + func flashAnimation(targetView: UIView, + repeatCount: Int, + _ completion: @escaping () -> Void) + { + targetView.alpha = 1.0 + UIView.animate(withDuration: 0.2, + delay: 0.0, + animations: { + targetView.alpha = 0.0 + }, completion: { [self] _ in + targetView.alpha = 1.0 + count += 1 + if repeatCount == count { + completion() + } else { + flashAnimation(targetView: targetView, + repeatCount: repeatCount, + completion) + } + }) + } +} diff --git a/Tetris/View/View/FieldView.swift b/Tetris/View/View/FieldView.swift index f1c3dfe..7cddd7c 100644 --- a/Tetris/View/View/FieldView.swift +++ b/Tetris/View/View/FieldView.swift @@ -9,7 +9,6 @@ import UIKit final class FieldView: UIView { - var barSize: CGFloat { frame.height / CGFloat(Tate) } @@ -49,7 +48,8 @@ final class FieldView: UIView { } func animation(bars: [[Bs]], - completion: @escaping () -> Void) { + completion: @escaping () -> Void) + { var tag = 1 var willAnimation = 0 var didAnimation = 0 @@ -59,7 +59,8 @@ final class FieldView: UIView { if isBar[yoko].status == .animation { willAnimation += 1 let bar = viewWithTag(tag) as! Bar - bar.flashAnimation { + let animation = Animation() + animation.flashAnimation(targetView: bar, repeatCount: 3) { didAnimation += 1 if willAnimation == didAnimation { completion() From 8224e4664ca685dac96988357d6c1f32b516cdce Mon Sep 17 00:00:00 2001 From: keisukeYamagishi Date: Fri, 5 Jan 2024 12:00:47 +0900 Subject: [PATCH 2/3] In the game, I've modified the layout. --- Tetris/View/ViewController/Game/Tetris.storyboard | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Tetris/View/ViewController/Game/Tetris.storyboard b/Tetris/View/ViewController/Game/Tetris.storyboard index 2c8139d..ed7a3bf 100644 --- a/Tetris/View/ViewController/Game/Tetris.storyboard +++ b/Tetris/View/ViewController/Game/Tetris.storyboard @@ -38,7 +38,7 @@ -