Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cross zan animation #9

Merged
merged 1 commit into from
Dec 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SamuraiTransition.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
ADDC02611DF99FEC009EEC45 /* UIView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADDC02601DF99FEC009EEC45 /* UIView+Extension.swift */; };
ADDC02641DFD332A009EEC45 /* CrossZanConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADDC02631DFD332A009EEC45 /* CrossZanConfig.swift */; };
C27839E71DF58ECF004B1E0C /* ZanViewConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = C27839E61DF58ECF004B1E0C /* ZanViewConfig.swift */; };
C2E5F6DE1DF806A30012CFE2 /* ZanViewConfigProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2E5F6DD1DF806A30012CFE2 /* ZanViewConfigProtocol.swift */; };
C2E5F6E01DF80D730012CFE2 /* SamuraiConfigProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2E5F6DF1DF80D730012CFE2 /* SamuraiConfigProtocol.swift */; };
Expand All @@ -23,6 +24,7 @@

/* Begin PBXFileReference section */
ADDC02601DF99FEC009EEC45 /* UIView+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Extension.swift"; sourceTree = "<group>"; };
ADDC02631DFD332A009EEC45 /* CrossZanConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CrossZanConfig.swift; sourceTree = "<group>"; };
C27839E61DF58ECF004B1E0C /* ZanViewConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZanViewConfig.swift; sourceTree = "<group>"; };
C2E5F6DD1DF806A30012CFE2 /* ZanViewConfigProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZanViewConfigProtocol.swift; sourceTree = "<group>"; };
C2E5F6DF1DF80D730012CFE2 /* SamuraiConfigProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SamuraiConfigProtocol.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -76,6 +78,7 @@
C2E5F6EB1DF82AC40012CFE2 /* HorizontalZanConfig.swift */,
C2E5F6E71DF825310012CFE2 /* VerticalZanConfig.swift */,
C2E5F6E91DF828830012CFE2 /* DiagonallyZanConfig.swift */,
ADDC02631DFD332A009EEC45 /* CrossZanConfig.swift */,
C27839E61DF58ECF004B1E0C /* ZanViewConfig.swift */,
C2E5F6DD1DF806A30012CFE2 /* ZanViewConfigProtocol.swift */,
C2E5F6DF1DF80D730012CFE2 /* SamuraiConfigProtocol.swift */,
Expand Down Expand Up @@ -169,6 +172,7 @@
C2F716861DE959FF00480CAB /* Zan.swift in Sources */,
C2E5F6DE1DF806A30012CFE2 /* ZanViewConfigProtocol.swift in Sources */,
C2E5F6EA1DF828830012CFE2 /* DiagonallyZanConfig.swift in Sources */,
ADDC02641DFD332A009EEC45 /* CrossZanConfig.swift in Sources */,
C2E5F6EC1DF82AC40012CFE2 /* HorizontalZanConfig.swift in Sources */,
C2E5F6E61DF8239F0012CFE2 /* OneLineZanProtocol.swift in Sources */,
C2E5F6E81DF825310012CFE2 /* VerticalZanConfig.swift in Sources */,
Expand Down
47 changes: 47 additions & 0 deletions SamuraiTransition/CrossZanConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// CrossZanConfig.swift
// SamuraiTransition
//
// Created by Takahiro Nishinobu on 2016/12/11.
// Copyright © 2016年 hachinobu. All rights reserved.
//

import Foundation

class CrossZanConfig: OneLineZanProtocol, SamuraiConfigProtocol {

let containerFrame: CGRect
let zanPoint: CGPoint
let width: CGFloat
let color: UIColor

//conform SamuraiConfigProtocol
lazy var lineLayers: [CAShapeLayer] = {
let oneCrossLayer = self.zanLineLayer(from: CGPoint(x: self.zanPoint.x, y: self.containerFrame.minY), end: CGPoint(x: self.zanPoint.x, y: self.containerFrame.maxY), width: self.width, color: self.color)
let otherCrossLayer = self.zanLineLayer(from: CGPoint(x: self.containerFrame.minX, y: self.zanPoint.y), end: CGPoint(x: self.containerFrame.maxX, y: self.zanPoint.y), width: self.width, color: self.color)
return [oneCrossLayer, otherCrossLayer]
}()

lazy var zanViewConfigList: [ZanViewConfigProtocol] = {

let leftTopRect = CGRect(x: self.containerFrame.minX, y: self.containerFrame.minY, width: self.zanPoint.x, height: self.zanPoint.y)
let rightTopRect = CGRect(x: leftTopRect.width, y: self.containerFrame.minY, width: self.containerFrame.width - leftTopRect.width, height: leftTopRect.height)
let leftBottomRect = CGRect(x: leftTopRect.minX, y: leftTopRect.maxY, width: leftTopRect.width, height: self.containerFrame.height - leftTopRect.height)
let rightBottomRect = CGRect(x: leftTopRect.maxX, y: rightTopRect.maxY, width: rightTopRect.width, height: leftBottomRect.height)

let leftTopConfig = ZanViewConfig(insideFrame: leftTopRect, outSideFrame: leftTopRect.offsetBy(dx: -leftTopRect.width, dy: -leftTopRect.height))
let rightTopConfig = ZanViewConfig(insideFrame: rightTopRect, outSideFrame: rightTopRect.offsetBy(dx: rightTopRect.width, dy: -rightTopRect.height))
let leftBottomConfig = ZanViewConfig(insideFrame: leftBottomRect, outSideFrame: leftBottomRect.offsetBy(dx: -leftBottomRect.width, dy: leftBottomRect.height))
let rightBottomConfig = ZanViewConfig(insideFrame: rightBottomRect, outSideFrame: rightBottomRect.offsetBy(dx: rightBottomRect.width, dy: rightBottomRect.height))

return [leftTopConfig, rightTopConfig, leftBottomConfig, rightBottomConfig]
}()

init(containerFrame: CGRect, zanPoint: CGPoint, width: CGFloat, color: UIColor) {
self.containerFrame = containerFrame
self.zanPoint = zanPoint
self.width = width
self.color = color
}

}
4 changes: 4 additions & 0 deletions SamuraiTransition/Zan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum Zan {
case horizontal
case vertical
case diagonally
case cross

func samuraiConfig(containerFrame: CGRect, zanPoint: CGPoint, width: CGFloat, color: UIColor) -> SamuraiConfigProtocol {

Expand All @@ -25,6 +26,9 @@ public enum Zan {

case .diagonally:
return DiagonallyZanConfig(containerFrame: containerFrame, zanPoint: zanPoint, width: width, color: color)

case .cross:
return CrossZanConfig(containerFrame: containerFrame, zanPoint: zanPoint, width: width, color: color)
}

}
Expand Down