Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4534c0dcd4 | |||
| b24752e27a | |||
| 22ef289da4 | |||
| 1428534fcc | |||
| 3ee0a8a606 | |||
| 0f35c65a48 | |||
| c578516270 | |||
| 1d00b258e9 | |||
| 37940a69eb | |||
| 739c698c02 | |||
| 3289f9c315 | |||
| 82f01134d2 | |||
| f6d7e82c98 | |||
| 5c8a416f5b | |||
| 0122f09e6b | |||
| 98a4fa1db9 | |||
| a766ceddbd | |||
| 6d961f5923 | |||
| cf2619bbd8 | |||
| d378620f8b | |||
| e02c17db4f | |||
| cb88f53fc6 | |||
| 5826edf31f | |||
| ec9a6fc6a0 | |||
| 6d45896997 | |||
| 0c2b2c49ee | |||
| bdb3ccb994 | |||
| 51627a3f3d | |||
| 68881fb3cc | |||
| 83d32f754b | |||
| 628a4bab8a | |||
| 2c9a57acdc | |||
| db7ca734e9 | |||
| f4f645548d | |||
| c520680100 | |||
| 04e27502df | |||
| 9f211f33af | |||
| 083d952ad7 | |||
| 7254460f60 | |||
| 9dd5b4c82d | |||
| 81c4a16180 | |||
| 4e55227fee | |||
| 3aec47f892 | |||
| b9769e418b | |||
| b29b6ed033 | |||
| 69e60152c8 | |||
| 2d2097033d | |||
| 2e7943b049 | |||
| 3968b56d02 | |||
| fc589564b4 | |||
| ef8abb6499 | |||
| 41df3a1714 | |||
| 5782a0fafa | |||
| 0652edf64d | |||
| 1fffcfb25e | |||
| 3f3a676a6d | |||
| 7a6175e8fb | |||
| 6cf24b1ee1 | |||
| c37e32ce3f | |||
| 38926b111a | |||
| dce71006c9 | |||
| 77ae3b58c9 | |||
| 2d23e4f7f3 | |||
| 7e95b925a5 |
@@ -0,0 +1 @@
|
||||
4.2
|
||||
@@ -1,6 +1,13 @@
|
||||
osx_image: xcode8
|
||||
osx_image: xcode9.2
|
||||
language: objective-c
|
||||
|
||||
xcode_project: CircleMenu.xcodeproj
|
||||
xcode_scheme: CircleMenu
|
||||
xcode_sdk: iphonesimulator
|
||||
scheme: CircleMenu
|
||||
xcode_sdk: iphonesimulator11.2
|
||||
|
||||
# SWIFT_VERSION: 4.0
|
||||
|
||||
# whitelist
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'CircleMenu'
|
||||
s.version = '2.0.4'
|
||||
s.version = '4.1.0'
|
||||
s.summary = 'Amazing animation with buttons'
|
||||
s.homepage = 'https://github.com/Ramotion/circle-menu'
|
||||
s.license = 'MIT'
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 46;
|
||||
objectVersion = 51;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
@@ -17,7 +17,6 @@
|
||||
841EC5911C58E898008872D5 /* CircleMenuButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841EC58F1C58E898008872D5 /* CircleMenuButton.swift */; };
|
||||
841EC5941C58F3E2008872D5 /* CircleMenuLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841EC5931C58F3E2008872D5 /* CircleMenuLoader.swift */; };
|
||||
8497460C1C6A1C5D001E7184 /* CircleMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841EC58D1C58E898008872D5 /* CircleMenu.swift */; };
|
||||
8497460D1C6A1C6D001E7184 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 84F248BD1C58E65F008F12C1 /* Assets.xcassets */; };
|
||||
8497460E1C6A1C9D001E7184 /* CircleMenuLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841EC5931C58F3E2008872D5 /* CircleMenuLoader.swift */; };
|
||||
8497460F1C6A1CA0001E7184 /* CircleMenuButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841EC58F1C58E898008872D5 /* CircleMenuButton.swift */; };
|
||||
84F248B71C58E65F008F12C1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F248B61C58E65F008F12C1 /* AppDelegate.swift */; };
|
||||
@@ -72,7 +71,6 @@
|
||||
84F248BB1C58E65F008F12C1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
84F248BD1C58E65F008F12C1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
84F248C01C58E65F008F12C1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||
84F248C21C58E65F008F12C1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
84F248C71C58E65F008F12C1 /* CircleMenuTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CircleMenuTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
84F248CB1C58E65F008F12C1 /* CircleMenuTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleMenuTests.swift; sourceTree = "<group>"; };
|
||||
84F248CD1C58E65F008F12C1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
@@ -168,7 +166,6 @@
|
||||
84F248BA1C58E65F008F12C1 /* Main.storyboard */,
|
||||
84F248BD1C58E65F008F12C1 /* Assets.xcassets */,
|
||||
84F248BF1C58E65F008F12C1 /* LaunchScreen.storyboard */,
|
||||
84F248C21C58E65F008F12C1 /* Info.plist */,
|
||||
);
|
||||
path = CircleMenu;
|
||||
sourceTree = "<group>";
|
||||
@@ -221,7 +218,6 @@
|
||||
84F248AF1C58E65F008F12C1 /* Sources */,
|
||||
84F248B01C58E65F008F12C1 /* Frameworks */,
|
||||
84F248B11C58E65F008F12C1 /* Resources */,
|
||||
846980FB1C59F398002D77BE /* swift lint */,
|
||||
8403F5851CFF2C2E007D0BD1 /* Embed Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
@@ -259,27 +255,28 @@
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0800;
|
||||
LastUpgradeCheck = 1020;
|
||||
ORGANIZATIONNAME = "Alex K.";
|
||||
TargetAttributes = {
|
||||
8403F5781CFF2C2E007D0BD1 = {
|
||||
CreatedOnToolsVersion = 7.3.1;
|
||||
LastSwiftMigration = 0900;
|
||||
LastSwiftMigration = 1020;
|
||||
};
|
||||
84F248B21C58E65F008F12C1 = {
|
||||
CreatedOnToolsVersion = 7.2;
|
||||
DevelopmentTeam = 34MUF9YXTA;
|
||||
LastSwiftMigration = 0900;
|
||||
LastSwiftMigration = 1020;
|
||||
};
|
||||
84F248C61C58E65F008F12C1 = {
|
||||
CreatedOnToolsVersion = 7.2;
|
||||
LastSwiftMigration = 1020;
|
||||
TestTargetID = 84F248B21C58E65F008F12C1;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 84F248AE1C58E65F008F12C1 /* Build configuration list for PBXProject "CircleMenu" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
compatibilityVersion = "Xcode 10.0";
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
@@ -319,29 +316,11 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
8497460D1C6A1C6D001E7184 /* Assets.xcassets in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXShellScriptBuildPhase section */
|
||||
846980FB1C59F398002D77BE /* swift lint */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputPaths = (
|
||||
);
|
||||
name = "swift lint";
|
||||
outputPaths = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"SwiftLint does not exist, download from https://github.com/realm/SwiftLint\"\nfi";
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
8403F5741CFF2C2E007D0BD1 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
@@ -424,12 +403,15 @@
|
||||
INFOPLIST_FILE = CircleMenu/Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
"@loader_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.CircleMenu;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = On;
|
||||
SWIFT_VERSION = 4.0;
|
||||
SWIFT_VERSION = 5.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
@@ -449,12 +431,15 @@
|
||||
INFOPLIST_FILE = CircleMenu/Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
"@loader_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.CircleMenu;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = On;
|
||||
SWIFT_VERSION = 4.0;
|
||||
SWIFT_VERSION = 5.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
@@ -465,18 +450,27 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
@@ -504,7 +498,7 @@
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 4.0;
|
||||
SWIFT_VERSION = 4.2;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -512,18 +506,27 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
@@ -543,8 +546,9 @@
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 4.0;
|
||||
SWIFT_COMPILATION_MODE = wholemodule;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
||||
SWIFT_VERSION = 4.2;
|
||||
VALIDATE_PRODUCT = YES;
|
||||
};
|
||||
name = Release;
|
||||
@@ -555,14 +559,17 @@
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
INFOPLIST_FILE = CircleMenu/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
OTHER_SWIFT_FLAGS = "";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.dev;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = On;
|
||||
SWIFT_VERSION = 4.0;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -572,14 +579,17 @@
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
INFOPLIST_FILE = CircleMenu/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
OTHER_SWIFT_FLAGS = "";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.dev;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = On;
|
||||
SWIFT_VERSION = 4.0;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
@@ -588,9 +598,14 @@
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
INFOPLIST_FILE = CircleMenuTests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
"@loader_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.CircleMenuTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CircleMenuDemo.app/CircleMenuDemo";
|
||||
};
|
||||
name = Debug;
|
||||
@@ -600,9 +615,14 @@
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
INFOPLIST_FILE = CircleMenuTests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
"@loader_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.CircleMenuTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CircleMenuDemo.app/CircleMenuDemo";
|
||||
};
|
||||
name = Release;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0800"
|
||||
LastUpgradeVersion = "1020"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
||||
@@ -13,32 +13,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
var window: UIWindow?
|
||||
|
||||
|
||||
func application(
|
||||
_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
||||
_: UIApplication,
|
||||
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func applicationWillResignActive(_ application: UIApplication) {
|
||||
|
||||
}
|
||||
|
||||
func applicationDidEnterBackground(_ application: UIApplication) {
|
||||
|
||||
}
|
||||
|
||||
func applicationWillEnterForeground(_ application: UIApplication) {
|
||||
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(_ application: UIApplication) {
|
||||
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,48 +1,119 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "20x20",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "icon-40.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "20x20",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "icon-60.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "icon-58.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "icon-87.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "40x40",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "icon-80.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "40x40",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "icon-120.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "icon-120.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "icon-180.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"size" : "20x20",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "icon-20.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "20x20",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "icon-40.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "icon-29.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "icon-58.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "40x40",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "icon-40.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "40x40",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "icon-80.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "76x76",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "icon-76.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "76x76",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "icon-152.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "83.5x83.5",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "icon-167.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "1024x1024",
|
||||
"idiom" : "ios-marketing",
|
||||
"filename" : "Ramotion1024.png",
|
||||
"scale" : "1x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
},
|
||||
"properties" : {
|
||||
"pre-rendered" : true
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 464 B |
|
After Width: | Height: | Size: 618 B |
|
After Width: | Height: | Size: 834 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
@@ -1,7 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
@@ -13,15 +18,35 @@
|
||||
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<animations/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2018 Ramotion. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="9MI-zG-4vW">
|
||||
<rect key="frame" x="16" y="630" width="343" height="17"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<color key="textColor" red="0.96862745100000003" green="0.96862745100000003" blue="0.96862745100000003" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Circle Menu" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VWz-1T-4Oe">
|
||||
<rect key="frame" x="123" y="319" width="129" height="30"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="25"/>
|
||||
<color key="textColor" red="0.96862745100000003" green="0.96862745100000003" blue="0.96862745100000003" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="0.058823529409999999" green="0.078431372550000003" blue="0.1529411765" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="9MI-zG-4vW" secondAttribute="trailing" constant="16" id="0Nd-zV-ifm"/>
|
||||
<constraint firstItem="VWz-1T-4Oe" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="AUS-9v-IDH"/>
|
||||
<constraint firstItem="xb3-aO-Qok" firstAttribute="top" secondItem="9MI-zG-4vW" secondAttribute="bottom" constant="20" id="FNC-OT-bh6"/>
|
||||
<constraint firstItem="9MI-zG-4vW" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" constant="16" id="GKi-1N-UzF"/>
|
||||
<constraint firstItem="VWz-1T-4Oe" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="j7f-9j-flx"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="53" y="375"/>
|
||||
<point key="canvasLocation" x="52" y="374.66266866566718"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
||||
|
||||
@@ -26,5 +26,9 @@
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIStatusBarStyle</key>
|
||||
<string>UIStatusBarStyleLightContent</string>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -9,67 +9,60 @@
|
||||
import UIKit
|
||||
|
||||
extension UIColor {
|
||||
static func color(_ red: Int, green: Int, blue: Int, alpha: Float) -> UIColor {
|
||||
return UIColor(
|
||||
red: 1.0 / 255.0 * CGFloat(red),
|
||||
green: 1.0 / 255.0 * CGFloat(green),
|
||||
blue: 1.0 / 255.0 * CGFloat(blue),
|
||||
alpha: CGFloat(alpha))
|
||||
}
|
||||
static func color(_ red: Int, green: Int, blue: Int, alpha: Float) -> UIColor {
|
||||
return UIColor(
|
||||
red: 1.0 / 255.0 * CGFloat(red),
|
||||
green: 1.0 / 255.0 * CGFloat(green),
|
||||
blue: 1.0 / 255.0 * CGFloat(blue),
|
||||
alpha: CGFloat(alpha))
|
||||
}
|
||||
}
|
||||
|
||||
class ViewController: UIViewController, CircleMenuDelegate {
|
||||
|
||||
// let colors = [UIColor.redColor(), UIColor.grayColor(), UIColor.greenColor(), UIColor.purpleColor()]
|
||||
let items: [(icon: String, color: UIColor)] = [
|
||||
("icon_home", UIColor(red:0.19, green:0.57, blue:1, alpha:1)),
|
||||
("icon_search", UIColor(red:0.22, green:0.74, blue:0, alpha:1)),
|
||||
("notifications-btn", UIColor(red:0.96, green:0.23, blue:0.21, alpha:1)),
|
||||
("settings-btn", UIColor(red:0.51, green:0.15, blue:1, alpha:1)),
|
||||
("nearby-btn", UIColor(red:1, green:0.39, blue:0, alpha:1)),
|
||||
|
||||
// let colors = [UIColor.redColor(), UIColor.grayColor(), UIColor.greenColor(), UIColor.purpleColor()]
|
||||
let items: [(icon: String, color: UIColor)] = [
|
||||
("icon_home", UIColor(red: 0.19, green: 0.57, blue: 1, alpha: 1)),
|
||||
("icon_search", UIColor(red: 0.22, green: 0.74, blue: 0, alpha: 1)),
|
||||
("notifications-btn", UIColor(red: 0.96, green: 0.23, blue: 0.21, alpha: 1)),
|
||||
("settings-btn", UIColor(red: 0.51, green: 0.15, blue: 1, alpha: 1)),
|
||||
("nearby-btn", UIColor(red: 1, green: 0.39, blue: 0, alpha: 1))
|
||||
]
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// add button
|
||||
// let button = CircleMenu(
|
||||
// frame: CGRect(x: 200, y: 200, width: 50, height: 50),
|
||||
// normalIcon:"icon_menu",
|
||||
// selectedIcon:"icon_close",
|
||||
// buttonsCount: 4,
|
||||
// duration: 4,
|
||||
// distance: 120)
|
||||
// button.backgroundColor = UIColor.lightGrayColor()
|
||||
// button.delegate = self
|
||||
// button.layer.cornerRadius = button.frame.size.width / 2.0
|
||||
// view.addSubview(button)
|
||||
|
||||
}
|
||||
|
||||
override func didReceiveMemoryWarning() {
|
||||
super.didReceiveMemoryWarning()
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
|
||||
// MARK: <CircleMenuDelegate>
|
||||
|
||||
func circleMenu(_ circleMenu: CircleMenu, willDisplay button: UIButton, atIndex: Int) {
|
||||
button.backgroundColor = items[atIndex].color
|
||||
|
||||
button.setImage(UIImage(named: items[atIndex].icon), for: .normal)
|
||||
|
||||
// set highlited image
|
||||
let highlightedImage = UIImage(named: items[atIndex].icon)?.withRenderingMode(.alwaysTemplate)
|
||||
button.setImage(highlightedImage, for: .highlighted)
|
||||
button.tintColor = UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.3)
|
||||
}
|
||||
|
||||
func circleMenu(_ circleMenu: CircleMenu, buttonWillSelected button: UIButton, atIndex: Int) {
|
||||
print("button will selected: \(atIndex)")
|
||||
}
|
||||
|
||||
func circleMenu(_ circleMenu: CircleMenu, buttonDidSelected button: UIButton, atIndex: Int) {
|
||||
print("button did selected: \(atIndex)")
|
||||
}
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// add button
|
||||
// let button = CircleMenu(
|
||||
// frame: CGRect(x: 200, y: 200, width: 50, height: 50),
|
||||
// normalIcon:"icon_menu",
|
||||
// selectedIcon:"icon_close",
|
||||
// buttonsCount: 4,
|
||||
// duration: 4,
|
||||
// distance: 120)
|
||||
// button.backgroundColor = UIColor.lightGrayColor()
|
||||
// button.delegate = self
|
||||
// button.layer.cornerRadius = button.frame.size.width / 2.0
|
||||
// view.addSubview(button)
|
||||
}
|
||||
|
||||
// MARK: <CircleMenuDelegate>
|
||||
|
||||
func circleMenu(_: CircleMenu, willDisplay button: UIButton, atIndex: Int) {
|
||||
button.backgroundColor = items[atIndex].color
|
||||
|
||||
button.setImage(UIImage(named: items[atIndex].icon), for: .normal)
|
||||
|
||||
// set highlited image
|
||||
let highlightedImage = UIImage(named: items[atIndex].icon)?.withRenderingMode(.alwaysTemplate)
|
||||
button.setImage(highlightedImage, for: .highlighted)
|
||||
button.tintColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3)
|
||||
}
|
||||
|
||||
func circleMenu(_: CircleMenu, buttonWillSelected _: UIButton, atIndex: Int) {
|
||||
print("button will selected: \(atIndex)")
|
||||
}
|
||||
|
||||
func circleMenu(_: CircleMenu, buttonDidSelected _: UIButton, atIndex: Int) {
|
||||
print("button did selected: \(atIndex)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,10 @@
|
||||
import UIKit
|
||||
|
||||
// MARK: helpers
|
||||
func Init<Type>(_ value: Type, block: (_ object: Type) -> Void) -> Type {
|
||||
block(value)
|
||||
return value
|
||||
|
||||
func customize<Type>(_ value: Type, block: (_ object: Type) -> Void) -> Type {
|
||||
block(value)
|
||||
return value
|
||||
}
|
||||
|
||||
// MARK: Protocol
|
||||
@@ -36,455 +37,514 @@ func Init<Type>(_ value: Type, block: (_ object: Type) -> Void) -> Type {
|
||||
* CircleMenuDelegate
|
||||
*/
|
||||
@objc public protocol CircleMenuDelegate {
|
||||
|
||||
/**
|
||||
Tells the delegate the circle menu is about to draw a button for a particular index.
|
||||
|
||||
- parameter circleMenu: The circle menu object informing the delegate of this impending event.
|
||||
- parameter button: A circle menu button object that circle menu is going to use when drawing the row. Don't change button.tag
|
||||
- parameter atIndex: An button index.
|
||||
*/
|
||||
@objc optional func circleMenu(_ circleMenu: CircleMenu, willDisplay button: UIButton, atIndex: Int)
|
||||
|
||||
/**
|
||||
Tells the delegate that a specified index is about to be selected.
|
||||
|
||||
- parameter circleMenu: A circle menu object informing the delegate about the impending selection.
|
||||
- parameter button: A selected circle menu button. Don't change button.tag
|
||||
- parameter atIndex: Selected button index
|
||||
*/
|
||||
@objc optional func circleMenu(_ circleMenu: CircleMenu, buttonWillSelected button: UIButton, atIndex: Int)
|
||||
|
||||
/**
|
||||
Tells the delegate that the specified index is now selected.
|
||||
|
||||
- parameter circleMenu: A circle menu object informing the delegate about the new index selection.
|
||||
- parameter button: A selected circle menu button. Don't change button.tag
|
||||
- parameter atIndex: Selected button index
|
||||
*/
|
||||
@objc optional func circleMenu(_ circleMenu: CircleMenu, buttonDidSelected button: UIButton, atIndex: Int)
|
||||
|
||||
/**
|
||||
Tells the delegate that the menu was collapsed - the cancel action.
|
||||
|
||||
- parameter circleMenu: A circle menu object informing the delegate about the new index selection.
|
||||
*/
|
||||
@objc optional func menuCollapsed(_ circleMenu: CircleMenu)
|
||||
|
||||
/**
|
||||
Tells the delegate the circle menu is about to draw a button for a particular index.
|
||||
|
||||
- parameter circleMenu: The circle menu object informing the delegate of this impending event.
|
||||
- parameter button: A circle menu button object that circle menu is going to use when drawing the row. Don't change button.tag
|
||||
- parameter atIndex: An button index.
|
||||
*/
|
||||
@objc optional func circleMenu(_ circleMenu: CircleMenu, willDisplay button: UIButton, atIndex: Int)
|
||||
|
||||
/**
|
||||
Tells the delegate that a specified index is about to be selected.
|
||||
|
||||
- parameter circleMenu: A circle menu object informing the delegate about the impending selection.
|
||||
- parameter button: A selected circle menu button. Don't change button.tag
|
||||
- parameter atIndex: Selected button index
|
||||
*/
|
||||
@objc optional func circleMenu(_ circleMenu: CircleMenu, buttonWillSelected button: UIButton, atIndex: Int)
|
||||
|
||||
/**
|
||||
Tells the delegate that the specified index is now selected.
|
||||
|
||||
- parameter circleMenu: A circle menu object informing the delegate about the new index selection.
|
||||
- parameter button: A selected circle menu button. Don't change button.tag
|
||||
- parameter atIndex: Selected button index
|
||||
*/
|
||||
@objc optional func circleMenu(_ circleMenu: CircleMenu, buttonDidSelected button: UIButton, atIndex: Int)
|
||||
|
||||
/**
|
||||
Tells the delegate that the menu was collapsed - the cancel action. Fires immediately on button press
|
||||
|
||||
- parameter circleMenu: A circle menu object informing the delegate about the new index selection.
|
||||
*/
|
||||
@objc optional func menuCollapsed(_ circleMenu: CircleMenu)
|
||||
|
||||
/**
|
||||
Tells the delegate that the menu was opened. Fires immediately on button press
|
||||
|
||||
- parameter circleMenu: A circle menu object informing the delegate about the new index selection.
|
||||
*/
|
||||
@objc optional func menuOpened(_ circleMenu: CircleMenu)
|
||||
}
|
||||
|
||||
// MARK: CircleMenu
|
||||
|
||||
/// A Button object with pop ups buttons
|
||||
open class CircleMenu: UIButton {
|
||||
|
||||
// MARK: properties
|
||||
|
||||
/// Buttons count
|
||||
@IBInspectable open var buttonsCount: Int = 3
|
||||
/// Circle animation duration
|
||||
@IBInspectable open var duration: Double = 2
|
||||
/// Distance between center button and buttons
|
||||
@IBInspectable open var distance: Float = 100
|
||||
/// Delay between show buttons
|
||||
@IBInspectable open var showDelay: Double = 0
|
||||
|
||||
/// The object that acts as the delegate of the circle menu.
|
||||
@IBOutlet weak open var delegate: AnyObject? //CircleMenuDelegate?
|
||||
|
||||
var buttons: [UIButton]?
|
||||
weak var platform: UIView?
|
||||
|
||||
fileprivate var customNormalIconView: UIImageView?
|
||||
fileprivate var customSelectedIconView: UIImageView?
|
||||
|
||||
/**
|
||||
Initializes and returns a circle menu object.
|
||||
|
||||
- parameter frame: A rectangle specifying the initial location and size of the circle menu in its superview’s coordinates.
|
||||
- parameter normalIcon: The image to use for the specified normal state.
|
||||
- parameter selectedIcon: The image to use for the specified selected state.
|
||||
- parameter buttonsCount: The number of buttons.
|
||||
- parameter duration: The duration, in seconds, of the animation.
|
||||
- parameter distance: Distance between center button and sub buttons.
|
||||
|
||||
- returns: A newly created circle menu.
|
||||
*/
|
||||
public init(frame: CGRect,
|
||||
normalIcon: String?,
|
||||
selectedIcon: String?,
|
||||
buttonsCount: Int = 3,
|
||||
duration: Double = 2,
|
||||
distance: Float = 100) {
|
||||
super.init(frame: frame)
|
||||
|
||||
if let icon = normalIcon {
|
||||
setImage(UIImage(named: icon), for: UIControlState())
|
||||
}
|
||||
|
||||
if let icon = selectedIcon {
|
||||
setImage(UIImage(named: icon), for: .selected)
|
||||
}
|
||||
|
||||
self.buttonsCount = buttonsCount
|
||||
self.duration = duration
|
||||
self.distance = distance
|
||||
|
||||
commonInit()
|
||||
}
|
||||
|
||||
required public init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
|
||||
commonInit()
|
||||
}
|
||||
|
||||
fileprivate func commonInit() {
|
||||
addActions()
|
||||
|
||||
customNormalIconView = addCustomImageView(state: UIControlState())
|
||||
|
||||
customSelectedIconView = addCustomImageView(state: .selected)
|
||||
if customSelectedIconView != nil {
|
||||
customSelectedIconView?.alpha = 0
|
||||
}
|
||||
setImage(UIImage(), for: UIControlState())
|
||||
setImage(UIImage(), for: .selected)
|
||||
|
||||
}
|
||||
|
||||
// MARK: methods
|
||||
|
||||
/**
|
||||
Hide button
|
||||
|
||||
- parameter duration: The duration, in seconds, of the animation.
|
||||
- parameter hideDelay: The time to delay, in seconds.
|
||||
*/
|
||||
open func hideButtons(_ duration: Double, hideDelay: Double = 0) {
|
||||
if buttons == nil {
|
||||
return
|
||||
}
|
||||
|
||||
buttonsAnimationIsShow(isShow: false, duration: duration, hideDelay: hideDelay)
|
||||
|
||||
tapBounceAnimation()
|
||||
tapRotatedAnimation(0.3, isSelected: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Check is sub buttons showed
|
||||
*/
|
||||
open func buttonsIsShown() -> Bool {
|
||||
guard let buttons = self.buttons else {
|
||||
return false
|
||||
}
|
||||
|
||||
for button in buttons {
|
||||
if button.alpha == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// MARK: create
|
||||
fileprivate func createButtons(platform: UIView) -> [UIButton] {
|
||||
var buttons = [UIButton]()
|
||||
|
||||
let step: Float = 360.0 / Float(self.buttonsCount)
|
||||
for index in 0..<self.buttonsCount {
|
||||
|
||||
let angle: Float = Float(index) * step
|
||||
let distance = Float(self.bounds.size.height/2.0)
|
||||
let button = Init(CircleMenuButton(size: self.bounds.size, platform: platform, distance:distance, angle: angle)) {
|
||||
$0.tag = index
|
||||
$0.addTarget(self, action: #selector(CircleMenu.buttonHandler(_:)), for: UIControlEvents.touchUpInside)
|
||||
$0.alpha = 0
|
||||
}
|
||||
buttons.append(button)
|
||||
}
|
||||
return buttons
|
||||
}
|
||||
|
||||
fileprivate func addCustomImageView(state: UIControlState) -> UIImageView? {
|
||||
guard let image = image(for: state) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let iconView = Init(UIImageView(image: image)) {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.contentMode = .center
|
||||
$0.isUserInteractionEnabled = false
|
||||
}
|
||||
addSubview(iconView)
|
||||
|
||||
// added constraints
|
||||
iconView.addConstraint(NSLayoutConstraint(item: iconView, attribute: .height, relatedBy: .equal, toItem: nil,
|
||||
attribute: .height, multiplier: 1, constant: bounds.size.height))
|
||||
|
||||
iconView.addConstraint(NSLayoutConstraint(item: iconView, attribute: .width, relatedBy: .equal, toItem: nil,
|
||||
attribute: .width, multiplier: 1, constant: bounds.size.width))
|
||||
|
||||
addConstraint(NSLayoutConstraint(item: self, attribute: .centerX, relatedBy: .equal, toItem: iconView,
|
||||
attribute: .centerX, multiplier: 1, constant:0))
|
||||
|
||||
addConstraint(NSLayoutConstraint(item: self, attribute: .centerY, relatedBy: .equal, toItem: iconView,
|
||||
attribute: .centerY, multiplier: 1, constant:0))
|
||||
|
||||
return iconView
|
||||
}
|
||||
|
||||
fileprivate func createPlatform() -> UIView {
|
||||
let platform = Init(UIView(frame: .zero)) {
|
||||
$0.backgroundColor = .clear
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
superview?.insertSubview(platform, belowSubview: self)
|
||||
|
||||
// constraints
|
||||
let sizeConstraints = [NSLayoutAttribute.width, .height].map {
|
||||
NSLayoutConstraint(item: platform,
|
||||
attribute: $0,
|
||||
relatedBy: .equal,
|
||||
toItem: nil,
|
||||
attribute: $0,
|
||||
multiplier: 1,
|
||||
constant: CGFloat(distance * Float(2.0)))
|
||||
}
|
||||
platform.addConstraints(sizeConstraints)
|
||||
|
||||
let centerConstraints = [NSLayoutAttribute.centerX, .centerY].map {
|
||||
NSLayoutConstraint(item: self,
|
||||
attribute: $0,
|
||||
relatedBy: .equal,
|
||||
toItem: platform,
|
||||
attribute: $0,
|
||||
multiplier: 1,
|
||||
constant:0)
|
||||
}
|
||||
superview?.addConstraints(centerConstraints)
|
||||
|
||||
return platform
|
||||
}
|
||||
|
||||
// MARK: configure
|
||||
fileprivate func addActions() {
|
||||
self.addTarget(self, action: #selector(CircleMenu.onTap), for: UIControlEvents.touchUpInside)
|
||||
}
|
||||
|
||||
// MARK: actions
|
||||
|
||||
@objc func onTap() {
|
||||
if buttonsIsShown() == false {
|
||||
let platform = createPlatform()
|
||||
buttons = createButtons(platform: platform)
|
||||
self.platform = platform
|
||||
}
|
||||
let isShow = !buttonsIsShown()
|
||||
let duration = isShow ? 0.5 : 0.2
|
||||
buttonsAnimationIsShow(isShow: isShow, duration: duration)
|
||||
|
||||
tapBounceAnimation()
|
||||
tapRotatedAnimation(0.3, isSelected: isShow)
|
||||
}
|
||||
|
||||
@objc func buttonHandler(_ sender: CircleMenuButton) {
|
||||
guard let platform = self.platform else { return }
|
||||
|
||||
delegate?.circleMenu?(self, buttonWillSelected: sender, atIndex: sender.tag)
|
||||
|
||||
let circle = CircleMenuLoader(radius: CGFloat(distance),
|
||||
strokeWidth: bounds.size.height,
|
||||
platform: platform,
|
||||
color: sender.backgroundColor)
|
||||
|
||||
if let container = sender.container { // rotation animation
|
||||
sender.rotationAnimation(container.angleZ + 360, duration: duration)
|
||||
container.superview?.bringSubview(toFront: container)
|
||||
}
|
||||
|
||||
if let buttons = buttons {
|
||||
circle.fillAnimation(duration, startAngle: -90 + Float(360 / buttons.count) * Float(sender.tag)) { [weak self] in
|
||||
self?.buttons?.forEach { $0.alpha = 0 }
|
||||
}
|
||||
circle.hideAnimation(0.5, delay: duration) { [weak self] in
|
||||
if self?.platform?.superview != nil { self?.platform?.removeFromSuperview() }
|
||||
}
|
||||
|
||||
hideCenterButton(duration: 0.3)
|
||||
showCenterButton(duration: 0.525, delay: duration)
|
||||
// MARK: properties
|
||||
|
||||
if customNormalIconView != nil && customSelectedIconView != nil {
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + duration, execute: {
|
||||
self.delegate?.circleMenu?(self, buttonDidSelected: sender, atIndex: sender.tag)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: animations
|
||||
|
||||
fileprivate func buttonsAnimationIsShow(isShow: Bool, duration: Double, hideDelay: Double = 0) {
|
||||
guard let buttons = self.buttons else {
|
||||
return
|
||||
}
|
||||
|
||||
let step: Float = 360.0 / Float(self.buttonsCount)
|
||||
for index in 0..<self.buttonsCount {
|
||||
guard case let button as CircleMenuButton = buttons[index] else { continue }
|
||||
let angle: Float = Float(index) * step
|
||||
if isShow == true {
|
||||
delegate?.circleMenu?(self, willDisplay: button, atIndex: index)
|
||||
|
||||
button.rotatedZ(angle: angle, animated: false, delay: Double(index) * showDelay)
|
||||
button.showAnimation(distance: distance, duration: duration, delay: Double(index) * showDelay)
|
||||
} else {
|
||||
button.hideAnimation(
|
||||
distance: Float(self.bounds.size.height / 2.0),
|
||||
duration: duration, delay: hideDelay)
|
||||
self.delegate?.menuCollapsed?(self)
|
||||
}
|
||||
}
|
||||
if isShow == false { // hide buttons and remove
|
||||
self.buttons = nil
|
||||
/// Buttons count
|
||||
@IBInspectable open var buttonsCount: Int = 3
|
||||
/// Circle animation duration
|
||||
@IBInspectable open var duration: Double = 2
|
||||
/// Distance between center button and buttons
|
||||
@IBInspectable open var distance: Float = 100
|
||||
/// Delay between show buttons
|
||||
@IBInspectable open var showDelay: Double = 0
|
||||
/// Start angle of the circle
|
||||
@IBInspectable open var startAngle: Float = 0
|
||||
/// End angle of the circle
|
||||
@IBInspectable open var endAngle: Float = 360
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + duration) {
|
||||
// Pop buttons radius, if nil use center button size
|
||||
open var subButtonsRadius: CGFloat?
|
||||
|
||||
// Show buttons event
|
||||
open var showButtonsEvent: UIControl.Event = UIControl.Event.touchUpInside {
|
||||
didSet {
|
||||
addActions(newEvent: showButtonsEvent, oldEvent: oldValue)
|
||||
}
|
||||
}
|
||||
|
||||
/// The object that acts as the delegate of the circle menu.
|
||||
@IBOutlet open weak var delegate: AnyObject? // CircleMenuDelegate?
|
||||
|
||||
var buttons: [UIButton]?
|
||||
weak var platform: UIView?
|
||||
|
||||
public var customNormalIconView: UIImageView?
|
||||
public var customSelectedIconView: UIImageView?
|
||||
|
||||
/**
|
||||
Initializes and returns a circle menu object.
|
||||
|
||||
- parameter frame: A rectangle specifying the initial location and size of the circle menu in its superview’s coordinates.
|
||||
- parameter normalIcon: The image to use for the specified normal state.
|
||||
- parameter selectedIcon: The image to use for the specified selected state.
|
||||
- parameter buttonsCount: The number of buttons.
|
||||
- parameter duration: The duration, in seconds, of the animation.
|
||||
- parameter distance: Distance between center button and sub buttons.
|
||||
|
||||
- returns: A newly created circle menu.
|
||||
*/
|
||||
public init(frame: CGRect,
|
||||
normalIcon: String?,
|
||||
selectedIcon: String?,
|
||||
buttonsCount: Int = 3,
|
||||
duration: Double = 2,
|
||||
distance: Float = 100) {
|
||||
super.init(frame: frame)
|
||||
|
||||
if let icon = normalIcon {
|
||||
setImage(UIImage(named: icon), for: .normal)
|
||||
}
|
||||
|
||||
if let icon = selectedIcon {
|
||||
setImage(UIImage(named: icon), for: .selected)
|
||||
}
|
||||
|
||||
self.buttonsCount = buttonsCount
|
||||
self.duration = duration
|
||||
self.distance = distance
|
||||
|
||||
commonInit()
|
||||
}
|
||||
|
||||
public required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
|
||||
commonInit()
|
||||
}
|
||||
|
||||
fileprivate func commonInit() {
|
||||
addActions(newEvent: showButtonsEvent)
|
||||
|
||||
customNormalIconView = addCustomImageView(state: .normal)
|
||||
|
||||
customSelectedIconView = addCustomImageView(state: .selected)
|
||||
customSelectedIconView?.alpha = 0
|
||||
|
||||
setImage(UIImage(), for: .normal)
|
||||
setImage(UIImage(), for: .selected)
|
||||
}
|
||||
|
||||
// MARK: methods
|
||||
|
||||
/**
|
||||
Hide button
|
||||
|
||||
- parameter duration: The duration, in seconds, of the animation.
|
||||
- parameter hideDelay: The time to delay, in seconds.
|
||||
*/
|
||||
open func hideButtons(_ duration: Double, hideDelay: Double = 0) {
|
||||
if buttons == nil {
|
||||
return
|
||||
}
|
||||
|
||||
buttonsAnimationIsShow(isShow: false, duration: duration, hideDelay: hideDelay)
|
||||
|
||||
tapBounceAnimation(duration: 0.5)
|
||||
tapRotatedAnimation(0.3, isSelected: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Check is sub buttons showed
|
||||
*/
|
||||
open func buttonsIsShown() -> Bool {
|
||||
guard let buttons = self.buttons else {
|
||||
return false
|
||||
}
|
||||
|
||||
for button in buttons {
|
||||
if button.alpha == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
open override func removeFromSuperview() {
|
||||
if self.platform?.superview != nil { self.platform?.removeFromSuperview() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func tapBounceAnimation() {
|
||||
self.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
|
||||
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 5,
|
||||
options: UIViewAnimationOptions.curveLinear,
|
||||
animations: { () -> Void in
|
||||
self.transform = CGAffineTransform(scaleX: 1, y: 1)
|
||||
},
|
||||
completion: nil)
|
||||
}
|
||||
|
||||
fileprivate func tapRotatedAnimation(_ duration: Float, isSelected: Bool) {
|
||||
|
||||
let addAnimations: (_ view: UIImageView, _ isShow: Bool) -> () = { (view, isShow) in
|
||||
var toAngle: Float = 180.0
|
||||
var fromAngle: Float = 0
|
||||
var fromScale = 1.0
|
||||
var toScale = 0.2
|
||||
var fromOpacity = 1
|
||||
var toOpacity = 0
|
||||
if isShow == true {
|
||||
toAngle = 0
|
||||
fromAngle = -180
|
||||
fromScale = 0.2
|
||||
toScale = 1.0
|
||||
fromOpacity = 0
|
||||
toOpacity = 1
|
||||
}
|
||||
|
||||
let rotation = Init(CABasicAnimation(keyPath: "transform.rotation")) {
|
||||
$0.duration = TimeInterval(duration)
|
||||
$0.toValue = (toAngle.degrees)
|
||||
$0.fromValue = (fromAngle.degrees)
|
||||
$0.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
||||
}
|
||||
let fade = Init(CABasicAnimation(keyPath: "opacity")) {
|
||||
$0.duration = TimeInterval(duration)
|
||||
$0.fromValue = fromOpacity
|
||||
$0.toValue = toOpacity
|
||||
$0.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
||||
$0.fillMode = kCAFillModeForwards
|
||||
$0.isRemovedOnCompletion = false
|
||||
}
|
||||
let scale = Init(CABasicAnimation(keyPath: "transform.scale")) {
|
||||
$0.duration = TimeInterval(duration)
|
||||
$0.toValue = toScale
|
||||
$0.fromValue = fromScale
|
||||
$0.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
||||
}
|
||||
|
||||
view.layer.add(rotation, forKey: nil)
|
||||
view.layer.add(fade, forKey: nil)
|
||||
view.layer.add(scale, forKey: nil)
|
||||
}
|
||||
|
||||
if let customNormalIconView = self.customNormalIconView {
|
||||
addAnimations(customNormalIconView, !isSelected)
|
||||
}
|
||||
if let customSelectedIconView = self.customSelectedIconView {
|
||||
addAnimations(customSelectedIconView, isSelected)
|
||||
super.removeFromSuperview()
|
||||
}
|
||||
|
||||
self.isSelected = isSelected
|
||||
self.alpha = isSelected ? 0.3 : 1
|
||||
}
|
||||
|
||||
fileprivate func hideCenterButton(duration: Double, delay: Double = 0) {
|
||||
UIView.animate( withDuration: TimeInterval(duration), delay: TimeInterval(delay),
|
||||
options: UIViewAnimationOptions.curveEaseOut,
|
||||
animations: { () -> Void in
|
||||
self.transform = CGAffineTransform(scaleX: 0.001, y: 0.001)
|
||||
}, completion: nil)
|
||||
}
|
||||
|
||||
fileprivate func showCenterButton(duration: Float, delay: Double) {
|
||||
UIView.animate( withDuration: TimeInterval(duration), delay: TimeInterval(delay), usingSpringWithDamping: 0.78,
|
||||
initialSpringVelocity: 0, options: UIViewAnimationOptions.curveLinear,
|
||||
animations: { () -> Void in
|
||||
self.transform = CGAffineTransform(scaleX: 1, y: 1)
|
||||
self.alpha = 1
|
||||
},
|
||||
completion: nil)
|
||||
|
||||
let rotation = Init(CASpringAnimation(keyPath: "transform.rotation")) {
|
||||
$0.duration = TimeInterval(1.5)
|
||||
$0.toValue = (0)
|
||||
$0.fromValue = (Float(-180).degrees)
|
||||
$0.damping = 10
|
||||
$0.initialVelocity = 0
|
||||
$0.beginTime = CACurrentMediaTime() + delay
|
||||
// MARK: create
|
||||
|
||||
fileprivate func createButtons(platform: UIView) -> [UIButton] {
|
||||
var buttons = [UIButton]()
|
||||
|
||||
let step = getArcStep()
|
||||
for index in 0 ..< buttonsCount {
|
||||
|
||||
let angle: Float = startAngle + Float(index) * step
|
||||
let distance = Float(bounds.size.height / 2.0)
|
||||
let buttonSize: CGSize
|
||||
if let subButtonsRadius = self.subButtonsRadius {
|
||||
buttonSize = CGSize(width: subButtonsRadius * 2, height: subButtonsRadius * 2)
|
||||
} else {
|
||||
buttonSize = bounds.size
|
||||
}
|
||||
let button = customize(CircleMenuButton(size: buttonSize, platform: platform, distance: distance, angle: angle)) {
|
||||
$0.tag = index
|
||||
$0.addTarget(self, action: #selector(CircleMenu.buttonHandler(_:)), for: UIControl.Event.touchUpInside)
|
||||
$0.alpha = 0
|
||||
}
|
||||
buttons.append(button)
|
||||
}
|
||||
return buttons
|
||||
}
|
||||
|
||||
let fade = Init(CABasicAnimation(keyPath: "opacity")) {
|
||||
$0.duration = TimeInterval(0.01)
|
||||
$0.toValue = 0
|
||||
$0.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
||||
$0.fillMode = kCAFillModeForwards
|
||||
$0.isRemovedOnCompletion = false
|
||||
$0.beginTime = CACurrentMediaTime() + delay
|
||||
|
||||
fileprivate func addCustomImageView(state: UIControl.State) -> UIImageView? {
|
||||
guard let image = image(for: state) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let iconView = customize(UIImageView(image: image)) {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.contentMode = .center
|
||||
$0.isUserInteractionEnabled = false
|
||||
}
|
||||
addSubview(iconView)
|
||||
|
||||
// added constraints
|
||||
iconView.addConstraint(NSLayoutConstraint(item: iconView, attribute: .height, relatedBy: .equal, toItem: nil,
|
||||
attribute: .height, multiplier: 1, constant: bounds.size.height))
|
||||
|
||||
iconView.addConstraint(NSLayoutConstraint(item: iconView, attribute: .width, relatedBy: .equal, toItem: nil,
|
||||
attribute: .width, multiplier: 1, constant: bounds.size.width))
|
||||
|
||||
addConstraint(NSLayoutConstraint(item: self, attribute: .centerX, relatedBy: .equal, toItem: iconView,
|
||||
attribute: .centerX, multiplier: 1, constant: 0))
|
||||
|
||||
addConstraint(NSLayoutConstraint(item: self, attribute: .centerY, relatedBy: .equal, toItem: iconView,
|
||||
attribute: .centerY, multiplier: 1, constant: 0))
|
||||
|
||||
return iconView
|
||||
}
|
||||
let show = Init(CABasicAnimation(keyPath: "opacity")) {
|
||||
$0.duration = TimeInterval(duration)
|
||||
$0.toValue = 1
|
||||
$0.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
||||
$0.fillMode = kCAFillModeForwards
|
||||
$0.isRemovedOnCompletion = false
|
||||
$0.beginTime = CACurrentMediaTime() + delay
|
||||
|
||||
fileprivate func createPlatform() -> UIView {
|
||||
let platform = customize(UIView(frame: .zero)) {
|
||||
$0.backgroundColor = .clear
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
superview?.insertSubview(platform, belowSubview: self)
|
||||
|
||||
// constraints
|
||||
let sizeConstraints = [NSLayoutConstraint.Attribute.width, .height].map {
|
||||
NSLayoutConstraint(item: platform,
|
||||
attribute: $0,
|
||||
relatedBy: .equal,
|
||||
toItem: nil,
|
||||
attribute: $0,
|
||||
multiplier: 1,
|
||||
constant: CGFloat(distance * Float(2.0)))
|
||||
}
|
||||
platform.addConstraints(sizeConstraints)
|
||||
|
||||
let centerConstraints = [NSLayoutConstraint.Attribute.centerX, .centerY].map {
|
||||
NSLayoutConstraint(item: self,
|
||||
attribute: $0,
|
||||
relatedBy: .equal,
|
||||
toItem: platform,
|
||||
attribute: $0,
|
||||
multiplier: 1,
|
||||
constant: 0)
|
||||
}
|
||||
superview?.addConstraints(centerConstraints)
|
||||
|
||||
return platform
|
||||
}
|
||||
|
||||
// MARK: configure
|
||||
|
||||
fileprivate func addActions(newEvent: UIControl.Event, oldEvent: UIControl.Event? = nil) {
|
||||
if let oldEvent = oldEvent { removeTarget(self, action: #selector(CircleMenu.onTap), for: oldEvent) }
|
||||
addTarget(self, action: #selector(CircleMenu.onTap), for: newEvent)
|
||||
}
|
||||
|
||||
/**
|
||||
Retrieves the incremental lengths between buttons. If the arc length is 360 degrees or more, the increments
|
||||
will evenly space out in a full circle. If the arc length is less than 360 degrees, the last button will be
|
||||
placed on the endAngle.
|
||||
*/
|
||||
fileprivate func getArcStep() -> Float {
|
||||
var arcLength = endAngle - startAngle
|
||||
var stepCount = buttonsCount
|
||||
|
||||
if arcLength < 360 {
|
||||
stepCount -= 1
|
||||
} else if arcLength > 360 {
|
||||
arcLength = 360
|
||||
}
|
||||
|
||||
return arcLength / Float(stepCount)
|
||||
}
|
||||
|
||||
// MARK: actions
|
||||
|
||||
private var isBounceAnimating: Bool = false
|
||||
|
||||
@objc func onTap() {
|
||||
guard isBounceAnimating == false else { return }
|
||||
isBounceAnimating = true
|
||||
|
||||
if buttonsIsShown() == false {
|
||||
let platform = createPlatform()
|
||||
buttons = createButtons(platform: platform)
|
||||
self.platform = platform
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()) {
|
||||
self.delegate?.menuOpened?(self)
|
||||
}
|
||||
}
|
||||
let isShow = !buttonsIsShown()
|
||||
let duration = isShow ? 0.5 : 0.2
|
||||
buttonsAnimationIsShow(isShow: isShow, duration: duration)
|
||||
|
||||
tapBounceAnimation(duration: 0.5) { [weak self] _ in self?.isBounceAnimating = false }
|
||||
tapRotatedAnimation(0.3, isSelected: isShow)
|
||||
}
|
||||
|
||||
@objc func buttonHandler(_ sender: CircleMenuButton) {
|
||||
guard let platform = self.platform else { return }
|
||||
|
||||
delegate?.circleMenu?(self, buttonWillSelected: sender, atIndex: sender.tag)
|
||||
|
||||
let strokeWidth: CGFloat
|
||||
if let radius = self.subButtonsRadius {
|
||||
strokeWidth = radius * 2
|
||||
} else {
|
||||
strokeWidth = bounds.size.height
|
||||
}
|
||||
|
||||
let circle = CircleMenuLoader(radius: CGFloat(distance),
|
||||
strokeWidth: strokeWidth,
|
||||
platform: platform,
|
||||
color: sender.backgroundColor)
|
||||
|
||||
if let container = sender.container { // rotation animation
|
||||
sender.rotationAnimation(container.angleZ + 360, duration: duration)
|
||||
container.superview?.bringSubviewToFront(container)
|
||||
}
|
||||
|
||||
let step = getArcStep()
|
||||
circle.fillAnimation(duration, startAngle: -90 + startAngle + step * Float(sender.tag)) { [weak self] in
|
||||
self?.buttons?.forEach { $0.alpha = 0 }
|
||||
}
|
||||
circle.hideAnimation(0.5, delay: duration) { [weak self] in
|
||||
if self?.platform?.superview != nil { self?.platform?.removeFromSuperview() }
|
||||
}
|
||||
|
||||
hideCenterButton(duration: 0.3)
|
||||
showCenterButton(duration: 0.525, delay: duration)
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + duration, execute: {
|
||||
self.delegate?.circleMenu?(self, buttonDidSelected: sender, atIndex: sender.tag)
|
||||
})
|
||||
}
|
||||
|
||||
// MARK: animations
|
||||
|
||||
fileprivate func buttonsAnimationIsShow(isShow: Bool, duration: Double, hideDelay: Double = 0) {
|
||||
guard let buttons = self.buttons else {
|
||||
return
|
||||
}
|
||||
|
||||
let step = getArcStep()
|
||||
for index in 0 ..< buttonsCount {
|
||||
guard case let button as CircleMenuButton = buttons[index] else { continue }
|
||||
if isShow == true {
|
||||
delegate?.circleMenu?(self, willDisplay: button, atIndex: index)
|
||||
let angle: Float = startAngle + Float(index) * step
|
||||
button.rotatedZ(angle: angle, animated: false, delay: Double(index) * showDelay)
|
||||
button.showAnimation(distance: distance, duration: duration, delay: Double(index) * showDelay)
|
||||
} else {
|
||||
button.hideAnimation(distance: Float(bounds.size.height / 2.0), duration: duration, delay: hideDelay)
|
||||
}
|
||||
}
|
||||
if isShow == false { // hide buttons and remove
|
||||
self.buttons = nil
|
||||
delegate?.menuCollapsed?(self)
|
||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + duration) {
|
||||
if self.platform?.superview != nil { self.platform?.removeFromSuperview() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func tapBounceAnimation(duration: TimeInterval, completion: ((Bool)->())? = nil) {
|
||||
transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
|
||||
UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 5,
|
||||
options: UIView.AnimationOptions.curveLinear,
|
||||
animations: { () -> Void in
|
||||
self.transform = CGAffineTransform(scaleX: 1, y: 1)
|
||||
},
|
||||
completion: completion)
|
||||
}
|
||||
|
||||
fileprivate func tapRotatedAnimation(_ duration: Float, isSelected: Bool) {
|
||||
|
||||
let addAnimations: (_ view: UIImageView, _ isShow: Bool) -> Void = { view, isShow in
|
||||
var toAngle: Float = 180.0
|
||||
var fromAngle: Float = 0
|
||||
var fromScale = 1.0
|
||||
var toScale = 0.2
|
||||
var fromOpacity = 1
|
||||
var toOpacity = 0
|
||||
if isShow == true {
|
||||
toAngle = 0
|
||||
fromAngle = -180
|
||||
fromScale = 0.2
|
||||
toScale = 1.0
|
||||
fromOpacity = 0
|
||||
toOpacity = 1
|
||||
}
|
||||
|
||||
let rotation = customize(CABasicAnimation(keyPath: "transform.rotation")) {
|
||||
$0.duration = TimeInterval(duration)
|
||||
$0.toValue = (toAngle.degrees)
|
||||
$0.fromValue = (fromAngle.degrees)
|
||||
$0.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
|
||||
}
|
||||
let fade = customize(CABasicAnimation(keyPath: "opacity")) {
|
||||
$0.duration = TimeInterval(duration)
|
||||
$0.fromValue = fromOpacity
|
||||
$0.toValue = toOpacity
|
||||
$0.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
|
||||
$0.fillMode = CAMediaTimingFillMode.forwards
|
||||
$0.isRemovedOnCompletion = false
|
||||
}
|
||||
let scale = customize(CABasicAnimation(keyPath: "transform.scale")) {
|
||||
$0.duration = TimeInterval(duration)
|
||||
$0.toValue = toScale
|
||||
$0.fromValue = fromScale
|
||||
$0.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
|
||||
}
|
||||
|
||||
view.layer.add(rotation, forKey: nil)
|
||||
view.layer.add(fade, forKey: nil)
|
||||
view.layer.add(scale, forKey: nil)
|
||||
}
|
||||
|
||||
if let customNormalIconView = self.customNormalIconView {
|
||||
addAnimations(customNormalIconView, !isSelected)
|
||||
}
|
||||
if let customSelectedIconView = self.customSelectedIconView {
|
||||
addAnimations(customSelectedIconView, isSelected)
|
||||
}
|
||||
|
||||
self.isSelected = isSelected
|
||||
alpha = isSelected ? 0.3 : 1
|
||||
}
|
||||
|
||||
fileprivate func hideCenterButton(duration: Double, delay: Double = 0) {
|
||||
UIView.animate(withDuration: TimeInterval(duration), delay: TimeInterval(delay),
|
||||
options: UIView.AnimationOptions.curveEaseOut,
|
||||
animations: { () -> Void in
|
||||
self.transform = CGAffineTransform(scaleX: 0.001, y: 0.001)
|
||||
}, completion: nil)
|
||||
}
|
||||
|
||||
fileprivate func showCenterButton(duration: Float, delay: Double) {
|
||||
UIView.animate(withDuration: TimeInterval(duration), delay: TimeInterval(delay), usingSpringWithDamping: 0.78,
|
||||
initialSpringVelocity: 0, options: UIView.AnimationOptions.curveLinear,
|
||||
animations: { () -> Void in
|
||||
self.transform = CGAffineTransform(scaleX: 1, y: 1)
|
||||
self.alpha = 1
|
||||
},
|
||||
completion: nil)
|
||||
|
||||
let rotation = customize(CASpringAnimation(keyPath: "transform.rotation")) {
|
||||
$0.duration = TimeInterval(1.5)
|
||||
$0.toValue = 0
|
||||
$0.fromValue = (Float(-180).degrees)
|
||||
$0.damping = 10
|
||||
$0.initialVelocity = 0
|
||||
$0.beginTime = CACurrentMediaTime() + delay
|
||||
}
|
||||
|
||||
let fade = customize(CABasicAnimation(keyPath: "opacity")) {
|
||||
$0.duration = TimeInterval(0.01)
|
||||
$0.toValue = 0
|
||||
$0.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
|
||||
$0.fillMode = CAMediaTimingFillMode.forwards
|
||||
$0.isRemovedOnCompletion = false
|
||||
$0.beginTime = CACurrentMediaTime() + delay
|
||||
}
|
||||
let show = customize(CABasicAnimation(keyPath: "opacity")) {
|
||||
$0.duration = TimeInterval(duration)
|
||||
$0.toValue = 1
|
||||
$0.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
|
||||
$0.fillMode = CAMediaTimingFillMode.forwards
|
||||
$0.isRemovedOnCompletion = false
|
||||
$0.beginTime = CACurrentMediaTime() + delay
|
||||
}
|
||||
|
||||
customNormalIconView?.layer.add(rotation, forKey: nil)
|
||||
customNormalIconView?.layer.add(show, forKey: nil)
|
||||
|
||||
customSelectedIconView?.layer.add(fade, forKey: nil)
|
||||
}
|
||||
|
||||
customNormalIconView?.layer.add(rotation, forKey: nil)
|
||||
customNormalIconView?.layer.add(show, forKey: nil)
|
||||
|
||||
customSelectedIconView?.layer.add(fade, forKey: nil)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: extension
|
||||
|
||||
internal extension Float {
|
||||
var radians: Float {
|
||||
return self * (Float(180) / Float.pi)
|
||||
}
|
||||
|
||||
var degrees: Float {
|
||||
return self * Float.pi / 180.0
|
||||
}
|
||||
var radians: Float {
|
||||
return self * (Float(180) / Float.pi)
|
||||
}
|
||||
|
||||
var degrees: Float {
|
||||
return self * Float.pi / 180.0
|
||||
}
|
||||
}
|
||||
|
||||
internal extension UIView {
|
||||
|
||||
var angleZ: Float {
|
||||
return atan2(Float(self.transform.b), Float(self.transform.a)).radians
|
||||
}
|
||||
|
||||
var angleZ: Float {
|
||||
return atan2(Float(transform.b), Float(transform.a)).radians
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,186 +24,187 @@
|
||||
import UIKit
|
||||
|
||||
internal class CircleMenuButton: UIButton {
|
||||
|
||||
// MARK: properties
|
||||
weak var container: UIView?
|
||||
|
||||
|
||||
// MARK: life cycle
|
||||
|
||||
init(size: CGSize, platform: UIView, distance: Float, angle: Float = 0) {
|
||||
super.init(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: size))
|
||||
|
||||
self.backgroundColor = UIColor(red: 0.79, green: 0.24, blue: 0.27, alpha: 1)
|
||||
self.layer.cornerRadius = size.height / 2.0
|
||||
|
||||
let aContainer = createContainer(CGSize(width: size.width, height:CGFloat(distance)), platform: platform)
|
||||
|
||||
// hack view for rotate
|
||||
let view = UIView(frame: CGRect(x: 0, y: 0, width: self.bounds.width, height: self.bounds.height))
|
||||
view.backgroundColor = UIColor.clear
|
||||
view.addSubview(self)
|
||||
//...
|
||||
|
||||
aContainer.addSubview(view)
|
||||
container = aContainer
|
||||
|
||||
view.layer.transform = CATransform3DMakeRotation(-CGFloat(angle.degrees), 0, 0, 1)
|
||||
|
||||
self.rotatedZ(angle: angle, animated: false)
|
||||
}
|
||||
|
||||
required internal init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
// MARK: configure
|
||||
fileprivate func createContainer(_ size: CGSize, platform: UIView) -> UIView {
|
||||
let container = Init(UIView(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: size))) {
|
||||
$0.backgroundColor = UIColor.clear
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.layer.anchorPoint = CGPoint(x: 0.5, y: 1)
|
||||
// MARK: properties
|
||||
|
||||
weak var container: UIView?
|
||||
|
||||
// MARK: life cycle
|
||||
|
||||
init(size: CGSize, platform: UIView, distance: Float, angle: Float = 0) {
|
||||
super.init(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: size))
|
||||
|
||||
backgroundColor = UIColor(red: 0.79, green: 0.24, blue: 0.27, alpha: 1)
|
||||
layer.cornerRadius = size.height / 2.0
|
||||
|
||||
let aContainer = createContainer(CGSize(width: size.width, height: CGFloat(distance)), platform: platform)
|
||||
|
||||
// hack view for rotate
|
||||
let view = UIView(frame: CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height))
|
||||
view.backgroundColor = UIColor.clear
|
||||
view.addSubview(self)
|
||||
// ...
|
||||
|
||||
aContainer.addSubview(view)
|
||||
container = aContainer
|
||||
|
||||
view.layer.transform = CATransform3DMakeRotation(-CGFloat(angle.degrees), 0, 0, 1)
|
||||
|
||||
rotatedZ(angle: angle, animated: false)
|
||||
}
|
||||
platform.addSubview(container)
|
||||
|
||||
// added constraints
|
||||
let height = NSLayoutConstraint(item: container,
|
||||
attribute: .height,
|
||||
relatedBy: .equal,
|
||||
toItem: nil,
|
||||
attribute: .height,
|
||||
multiplier: 1,
|
||||
constant: size.height)
|
||||
height.identifier = "height"
|
||||
container.addConstraint(height)
|
||||
|
||||
container.addConstraint(NSLayoutConstraint(item: container,
|
||||
attribute: .width,
|
||||
relatedBy: .equal,
|
||||
toItem: nil,
|
||||
attribute: .width,
|
||||
multiplier: 1,
|
||||
constant: size.width))
|
||||
|
||||
platform.addConstraint(NSLayoutConstraint(item: platform,
|
||||
attribute: .centerX,
|
||||
relatedBy: .equal,
|
||||
toItem: container,
|
||||
attribute: .centerX,
|
||||
multiplier: 1,
|
||||
constant:0))
|
||||
|
||||
platform.addConstraint(NSLayoutConstraint(item: platform,
|
||||
attribute: .centerY,
|
||||
relatedBy: .equal,
|
||||
toItem: container,
|
||||
attribute: .centerY,
|
||||
multiplier: 1,
|
||||
constant:0))
|
||||
|
||||
return container
|
||||
}
|
||||
|
||||
// MARK: methods
|
||||
|
||||
internal func rotatedZ(angle: Float, animated: Bool, duration: Double = 0, delay: Double = 0) {
|
||||
guard let container = self.container else {
|
||||
fatalError("contaner don't create")
|
||||
|
||||
internal required init?(coder _: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
let rotateTransform = CATransform3DMakeRotation(CGFloat(angle.degrees), 0, 0, 1)
|
||||
if animated {
|
||||
UIView.animate(
|
||||
withDuration: duration,
|
||||
delay: delay,
|
||||
options: UIViewAnimationOptions(),
|
||||
animations: { () -> Void in
|
||||
container.layer.transform = rotateTransform
|
||||
},
|
||||
completion: nil)
|
||||
} else {
|
||||
container.layer.transform = rotateTransform
|
||||
|
||||
// MARK: configure
|
||||
|
||||
fileprivate func createContainer(_ size: CGSize, platform: UIView) -> UIView {
|
||||
let container = customize(UIView(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: size))) {
|
||||
$0.backgroundColor = UIColor.clear
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.layer.anchorPoint = CGPoint(x: 0.5, y: 1)
|
||||
}
|
||||
platform.addSubview(container)
|
||||
|
||||
// added constraints
|
||||
let height = NSLayoutConstraint(item: container,
|
||||
attribute: .height,
|
||||
relatedBy: .equal,
|
||||
toItem: nil,
|
||||
attribute: .height,
|
||||
multiplier: 1,
|
||||
constant: size.height)
|
||||
height.identifier = "height"
|
||||
container.addConstraint(height)
|
||||
|
||||
container.addConstraint(NSLayoutConstraint(item: container,
|
||||
attribute: .width,
|
||||
relatedBy: .equal,
|
||||
toItem: nil,
|
||||
attribute: .width,
|
||||
multiplier: 1,
|
||||
constant: size.width))
|
||||
|
||||
platform.addConstraint(NSLayoutConstraint(item: platform,
|
||||
attribute: .centerX,
|
||||
relatedBy: .equal,
|
||||
toItem: container,
|
||||
attribute: .centerX,
|
||||
multiplier: 1,
|
||||
constant: 0))
|
||||
|
||||
platform.addConstraint(NSLayoutConstraint(item: platform,
|
||||
attribute: .centerY,
|
||||
relatedBy: .equal,
|
||||
toItem: container,
|
||||
attribute: .centerY,
|
||||
multiplier: 1,
|
||||
constant: 0))
|
||||
|
||||
return container
|
||||
}
|
||||
|
||||
// MARK: methods
|
||||
|
||||
internal func rotatedZ(angle: Float, animated: Bool, duration: Double = 0, delay: Double = 0) {
|
||||
guard let container = self.container else {
|
||||
fatalError("contaner don't create")
|
||||
}
|
||||
|
||||
let rotateTransform = CATransform3DMakeRotation(CGFloat(angle.degrees), 0, 0, 1)
|
||||
if animated {
|
||||
UIView.animate(
|
||||
withDuration: duration,
|
||||
delay: delay,
|
||||
options: UIView.AnimationOptions(),
|
||||
animations: { () -> Void in
|
||||
container.layer.transform = rotateTransform
|
||||
},
|
||||
completion: nil)
|
||||
} else {
|
||||
container.layer.transform = rotateTransform
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Animations
|
||||
|
||||
internal extension CircleMenuButton {
|
||||
|
||||
internal func showAnimation(distance: Float, duration: Double, delay: Double = 0) {
|
||||
guard let heightConstraint = (self.container?.constraints.filter {$0.identifier == "height"})?.first else {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
self.transform = CGAffineTransform(scaleX: 0, y: 0)
|
||||
self.container?.superview?.layoutIfNeeded()
|
||||
|
||||
self.alpha = 0
|
||||
|
||||
heightConstraint.constant = CGFloat(distance)
|
||||
UIView.animate(
|
||||
withDuration: duration,
|
||||
delay: delay,
|
||||
usingSpringWithDamping: 0.7,
|
||||
initialSpringVelocity: 0,
|
||||
options: UIViewAnimationOptions.curveLinear,
|
||||
animations: { () -> Void in
|
||||
self.container?.superview?.layoutIfNeeded()
|
||||
self.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
|
||||
self.alpha = 1
|
||||
}, completion: { (success) -> Void in
|
||||
})
|
||||
}
|
||||
|
||||
internal func hideAnimation(distance: Float, duration: Double, delay: Double = 0) {
|
||||
guard let heightConstraint = (self.container?.constraints.filter {$0.identifier == "height"})?.first else {
|
||||
return
|
||||
}
|
||||
|
||||
heightConstraint.constant = CGFloat(distance)
|
||||
UIView.animate(
|
||||
withDuration: duration,
|
||||
delay: delay,
|
||||
options: UIViewAnimationOptions.curveEaseIn,
|
||||
animations: { () -> Void in
|
||||
self.container?.superview?.layoutIfNeeded()
|
||||
self.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
|
||||
}, completion: { (success) -> Void in
|
||||
self.alpha = 0
|
||||
|
||||
if let _ = self.container {
|
||||
self.container?.removeFromSuperview() // remove container
|
||||
|
||||
func showAnimation(distance: Float, duration: Double, delay: Double = 0) {
|
||||
guard let heightConstraint = (self.container?.constraints.filter { $0.identifier == "height" })?.first else {
|
||||
fatalError()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
internal func changeDistance(_ distance: CGFloat, animated: Bool, duration: Double = 0, delay: Double = 0) {
|
||||
|
||||
guard let heightConstraint = (self.container?.constraints.filter {$0.identifier == "height"})?.first else {
|
||||
fatalError()
|
||||
|
||||
transform = CGAffineTransform(scaleX: 0, y: 0)
|
||||
container?.superview?.layoutIfNeeded()
|
||||
|
||||
alpha = 0
|
||||
|
||||
heightConstraint.constant = CGFloat(distance)
|
||||
UIView.animate(
|
||||
withDuration: duration,
|
||||
delay: delay,
|
||||
usingSpringWithDamping: 0.7,
|
||||
initialSpringVelocity: 0,
|
||||
options: UIView.AnimationOptions.curveLinear,
|
||||
animations: { () -> Void in
|
||||
self.container?.superview?.layoutIfNeeded()
|
||||
self.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
|
||||
self.alpha = 1
|
||||
}, completion: { (_) -> Void in
|
||||
})
|
||||
}
|
||||
|
||||
heightConstraint.constant = distance
|
||||
|
||||
UIView.animate(
|
||||
withDuration: duration,
|
||||
delay: delay,
|
||||
options: UIViewAnimationOptions.curveEaseIn,
|
||||
animations: { () -> Void in
|
||||
self.container?.superview?.layoutIfNeeded()
|
||||
},
|
||||
completion: nil)
|
||||
}
|
||||
|
||||
// MARK: layer animation
|
||||
|
||||
internal func rotationAnimation(_ angle: Float, duration: Double) {
|
||||
let rotation = Init(CABasicAnimation(keyPath: "transform.rotation")) {
|
||||
$0.duration = TimeInterval(duration)
|
||||
$0.toValue = (angle.degrees)
|
||||
$0.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
||||
|
||||
func hideAnimation(distance: Float, duration: Double, delay: Double = 0) {
|
||||
guard let heightConstraint = (self.container?.constraints.filter { $0.identifier == "height" })?.first else {
|
||||
return
|
||||
}
|
||||
|
||||
heightConstraint.constant = CGFloat(distance)
|
||||
UIView.animate(
|
||||
withDuration: duration,
|
||||
delay: delay,
|
||||
options: UIView.AnimationOptions.curveEaseIn,
|
||||
animations: { () -> Void in
|
||||
self.container?.superview?.layoutIfNeeded()
|
||||
self.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
|
||||
}, completion: { (_) -> Void in
|
||||
self.alpha = 0
|
||||
|
||||
if let _ = self.container {
|
||||
self.container?.removeFromSuperview() // remove container
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func changeDistance(_ distance: CGFloat, animated _: Bool, duration: Double = 0, delay: Double = 0) {
|
||||
|
||||
guard let heightConstraint = (self.container?.constraints.filter { $0.identifier == "height" })?.first else {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
heightConstraint.constant = distance
|
||||
|
||||
UIView.animate(
|
||||
withDuration: duration,
|
||||
delay: delay,
|
||||
options: UIView.AnimationOptions.curveEaseIn,
|
||||
animations: { () -> Void in
|
||||
self.container?.superview?.layoutIfNeeded()
|
||||
},
|
||||
completion: nil)
|
||||
}
|
||||
|
||||
// MARK: layer animation
|
||||
|
||||
func rotationAnimation(_ angle: Float, duration: Double) {
|
||||
let rotation = customize(CABasicAnimation(keyPath: "transform.rotation")) {
|
||||
$0.duration = TimeInterval(duration)
|
||||
$0.toValue = (angle.degrees)
|
||||
$0.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
|
||||
}
|
||||
container?.layer.add(rotation, forKey: "rotation")
|
||||
}
|
||||
container?.layer.add(rotation, forKey: "rotation")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,134 +26,137 @@ import Foundation
|
||||
import UIKit
|
||||
|
||||
internal class CircleMenuLoader: UIView {
|
||||
|
||||
// MARK: properties
|
||||
var circle: CAShapeLayer?
|
||||
|
||||
// MARK: life cycle
|
||||
internal init(radius: CGFloat, strokeWidth: CGFloat, platform: UIView, color: UIColor?) {
|
||||
super.init(frame: CGRect(x: 0, y: 0, width: radius, height: radius))
|
||||
|
||||
platform.addSubview(self)
|
||||
|
||||
circle = createCircle(radius, strokeWidth: strokeWidth, color: color)
|
||||
createConstraints(platform: platform, radius: radius)
|
||||
|
||||
let circleFrame = CGRect(
|
||||
x: radius * 2 - strokeWidth,
|
||||
y: radius - strokeWidth / 2,
|
||||
width: strokeWidth,
|
||||
height: strokeWidth)
|
||||
createRoundView(circleFrame, color: color)
|
||||
|
||||
backgroundColor = UIColor.clear
|
||||
}
|
||||
|
||||
required internal init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
// MARK: create
|
||||
fileprivate func createCircle(_ radius: CGFloat, strokeWidth: CGFloat, color: UIColor?) -> CAShapeLayer {
|
||||
|
||||
let circlePath = UIBezierPath(
|
||||
arcCenter: CGPoint(x: radius, y: radius),
|
||||
radius: CGFloat(radius) - strokeWidth / 2.0,
|
||||
startAngle: CGFloat(0),
|
||||
endAngle:CGFloat.pi * 2,
|
||||
clockwise: true)
|
||||
|
||||
let circle = Init(CAShapeLayer()) {
|
||||
$0.path = circlePath.cgPath
|
||||
$0.fillColor = UIColor.clear.cgColor
|
||||
$0.strokeColor = color?.cgColor
|
||||
$0.lineWidth = strokeWidth
|
||||
|
||||
// MARK: properties
|
||||
|
||||
var circle: CAShapeLayer?
|
||||
|
||||
// MARK: life cycle
|
||||
|
||||
internal init(radius: CGFloat, strokeWidth: CGFloat, platform: UIView, color: UIColor?) {
|
||||
super.init(frame: CGRect(x: 0, y: 0, width: radius, height: radius))
|
||||
|
||||
platform.addSubview(self)
|
||||
|
||||
circle = createCircle(radius, strokeWidth: strokeWidth, color: color)
|
||||
createConstraints(platform: platform, radius: radius)
|
||||
|
||||
let circleFrame = CGRect(
|
||||
x: radius * 2 - strokeWidth,
|
||||
y: radius - strokeWidth / 2,
|
||||
width: strokeWidth,
|
||||
height: strokeWidth)
|
||||
createRoundView(circleFrame, color: color)
|
||||
|
||||
backgroundColor = UIColor.clear
|
||||
}
|
||||
|
||||
self.layer.addSublayer(circle)
|
||||
return circle
|
||||
}
|
||||
|
||||
fileprivate func createConstraints(platform: UIView, radius: CGFloat) {
|
||||
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
// added constraints
|
||||
let sizeConstraints = [NSLayoutAttribute.width, .height].map {
|
||||
NSLayoutConstraint(item: self,
|
||||
attribute: $0,
|
||||
relatedBy: .equal,
|
||||
toItem: nil,
|
||||
attribute: $0,
|
||||
multiplier: 1,
|
||||
constant: radius * 2.0)
|
||||
|
||||
internal required init?(coder _: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
addConstraints(sizeConstraints)
|
||||
|
||||
let centerConstaraints = [NSLayoutAttribute.centerY, .centerX].map {
|
||||
NSLayoutConstraint(item: platform,
|
||||
attribute: $0,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: $0,
|
||||
multiplier: 1,
|
||||
constant:0)
|
||||
|
||||
// MARK: create
|
||||
|
||||
fileprivate func createCircle(_ radius: CGFloat, strokeWidth: CGFloat, color: UIColor?) -> CAShapeLayer {
|
||||
|
||||
let circlePath = UIBezierPath(
|
||||
arcCenter: CGPoint(x: radius, y: radius),
|
||||
radius: CGFloat(radius) - strokeWidth / 2.0,
|
||||
startAngle: CGFloat(0),
|
||||
endAngle: CGFloat.pi * 2,
|
||||
clockwise: true)
|
||||
|
||||
let circle = customize(CAShapeLayer()) {
|
||||
$0.path = circlePath.cgPath
|
||||
$0.fillColor = UIColor.clear.cgColor
|
||||
$0.strokeColor = color?.cgColor
|
||||
$0.lineWidth = strokeWidth
|
||||
}
|
||||
|
||||
layer.addSublayer(circle)
|
||||
return circle
|
||||
}
|
||||
platform.addConstraints(centerConstaraints)
|
||||
}
|
||||
|
||||
internal func createRoundView(_ rect: CGRect, color: UIColor?) {
|
||||
let roundView = Init(UIView(frame: rect)) {
|
||||
$0.backgroundColor = UIColor.black
|
||||
$0.layer.cornerRadius = rect.size.width / 2.0
|
||||
$0.backgroundColor = color
|
||||
|
||||
fileprivate func createConstraints(platform: UIView, radius: CGFloat) {
|
||||
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
// added constraints
|
||||
let sizeConstraints = [NSLayoutConstraint.Attribute.width, .height].map {
|
||||
NSLayoutConstraint(item: self,
|
||||
attribute: $0,
|
||||
relatedBy: .equal,
|
||||
toItem: nil,
|
||||
attribute: $0,
|
||||
multiplier: 1,
|
||||
constant: radius * 2.0)
|
||||
}
|
||||
addConstraints(sizeConstraints)
|
||||
|
||||
let centerConstaraints = [NSLayoutConstraint.Attribute.centerY, .centerX].map {
|
||||
NSLayoutConstraint(item: platform,
|
||||
attribute: $0,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: $0,
|
||||
multiplier: 1,
|
||||
constant: 0)
|
||||
}
|
||||
platform.addConstraints(centerConstaraints)
|
||||
}
|
||||
addSubview(roundView)
|
||||
}
|
||||
|
||||
// MARK: animations
|
||||
|
||||
internal func fillAnimation(_ duration: Double, startAngle: Float, completion: @escaping () -> Void) {
|
||||
guard circle != nil else {
|
||||
return
|
||||
|
||||
internal func createRoundView(_ rect: CGRect, color: UIColor?) {
|
||||
let roundView = customize(UIView(frame: rect)) {
|
||||
$0.backgroundColor = UIColor.black
|
||||
$0.layer.cornerRadius = rect.size.width / 2.0
|
||||
$0.backgroundColor = color
|
||||
}
|
||||
addSubview(roundView)
|
||||
}
|
||||
|
||||
let rotateTransform = CATransform3DMakeRotation(CGFloat(startAngle.degrees), 0, 0, 1)
|
||||
layer.transform = rotateTransform
|
||||
|
||||
CATransaction.begin()
|
||||
CATransaction.setCompletionBlock(completion)
|
||||
let animation = Init(CABasicAnimation(keyPath: "strokeEnd")) {
|
||||
$0.duration = CFTimeInterval(duration)
|
||||
$0.fromValue = (0)
|
||||
$0.toValue = (1)
|
||||
$0.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
||||
|
||||
// MARK: animations
|
||||
|
||||
internal func fillAnimation(_ duration: Double, startAngle: Float, completion: @escaping () -> Void) {
|
||||
guard circle != nil else {
|
||||
return
|
||||
}
|
||||
|
||||
let rotateTransform = CATransform3DMakeRotation(CGFloat(startAngle.degrees), 0, 0, 1)
|
||||
layer.transform = rotateTransform
|
||||
|
||||
CATransaction.begin()
|
||||
CATransaction.setCompletionBlock(completion)
|
||||
let animation = customize(CABasicAnimation(keyPath: "strokeEnd")) {
|
||||
$0.duration = CFTimeInterval(duration)
|
||||
$0.fromValue = 0
|
||||
$0.toValue = 1
|
||||
$0.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
|
||||
}
|
||||
circle?.add(animation, forKey: nil)
|
||||
CATransaction.commit()
|
||||
}
|
||||
circle?.add(animation, forKey: nil)
|
||||
CATransaction.commit()
|
||||
}
|
||||
|
||||
internal func hideAnimation(_ duration: CGFloat, delay: Double, completion: @escaping () -> Void) {
|
||||
|
||||
let scale = Init(CABasicAnimation(keyPath: "transform.scale")) {
|
||||
$0.toValue = 1.2
|
||||
$0.duration = CFTimeInterval(duration)
|
||||
$0.fillMode = kCAFillModeForwards
|
||||
$0.isRemovedOnCompletion = false
|
||||
$0.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
|
||||
$0.beginTime = CACurrentMediaTime() + delay
|
||||
|
||||
internal func hideAnimation(_ duration: CGFloat, delay: Double, completion: @escaping () -> Void) {
|
||||
|
||||
let scale = customize(CABasicAnimation(keyPath: "transform.scale")) {
|
||||
$0.toValue = 1.2
|
||||
$0.duration = CFTimeInterval(duration)
|
||||
$0.fillMode = CAMediaTimingFillMode.forwards
|
||||
$0.isRemovedOnCompletion = false
|
||||
$0.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
|
||||
$0.beginTime = CACurrentMediaTime() + delay
|
||||
}
|
||||
layer.add(scale, forKey: nil)
|
||||
|
||||
UIView.animate(
|
||||
withDuration: CFTimeInterval(duration),
|
||||
delay: delay,
|
||||
options: UIView.AnimationOptions.curveEaseIn,
|
||||
animations: { () -> Void in
|
||||
self.alpha = 0
|
||||
},
|
||||
completion: { (_) -> Void in
|
||||
self.removeFromSuperview()
|
||||
completion()
|
||||
})
|
||||
}
|
||||
layer.add(scale, forKey: nil)
|
||||
|
||||
UIView.animate(
|
||||
withDuration: CFTimeInterval(duration),
|
||||
delay: delay,
|
||||
options: UIViewAnimationOptions.curveEaseIn,
|
||||
animations: { () -> Void in
|
||||
self.alpha = 0
|
||||
},
|
||||
completion: { (success) -> Void in
|
||||
self.removeFromSuperview()
|
||||
completion()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,25 +6,23 @@
|
||||
// Copyright © 2016 Alex K. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import CircleMenu
|
||||
import XCTest
|
||||
|
||||
class CircleMenuTests: XCTestCase {
|
||||
|
||||
let buttonsCount = 4
|
||||
|
||||
let circleMenu = CircleMenu(
|
||||
frame: CGRect(x: 200, y: 200, width: 50, height: 50),
|
||||
normalIcon:"icon_menu",
|
||||
selectedIcon:"icon_close",
|
||||
buttonsCount: 4,
|
||||
duration: 4,
|
||||
distance: 120)
|
||||
frame: CGRect(x: 200, y: 200, width: 50, height: 50),
|
||||
normalIcon: "icon_menu",
|
||||
selectedIcon: "icon_close",
|
||||
buttonsCount: 4,
|
||||
duration: 4,
|
||||
distance: 120)
|
||||
|
||||
let view = UIView()
|
||||
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
circleMenu.buttonsCount = buttonsCount
|
||||
@@ -33,7 +31,6 @@ class CircleMenuTests: XCTestCase {
|
||||
|
||||
override func tearDown() {
|
||||
super.tearDown()
|
||||
|
||||
}
|
||||
|
||||
func testCircleMenuShowButtons() {
|
||||
@@ -47,7 +44,6 @@ class CircleMenuTests: XCTestCase {
|
||||
XCTAssertEqual(circleMenu.buttons?.count, buttonsCount, "button is created")
|
||||
}
|
||||
|
||||
|
||||
func testCircleMenuHideButtons() {
|
||||
// given
|
||||
circleMenu.onTap()
|
||||
@@ -59,13 +55,12 @@ class CircleMenuTests: XCTestCase {
|
||||
XCTAssertNil(circleMenu.buttons, "button is removed")
|
||||
}
|
||||
|
||||
|
||||
func testCircleMenuHideButtonsAfterAnimation() {
|
||||
// given
|
||||
circleMenu.onTap()
|
||||
|
||||
// when
|
||||
circleMenu.buttonHandler((circleMenu.buttons?.first)!)
|
||||
circleMenu.buttonHandler((circleMenu.buttons?.first)! as! CircleMenuButton)
|
||||
|
||||
// then
|
||||
XCTAssertNil(circleMenu.buttons, "button is removed")
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
// swift-tools-version:5.1
|
||||
//
|
||||
// Package.swift
|
||||
//
|
||||
// Copyright (c) Ramotion (https://www.ramotion.com/)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "CircleMenu",
|
||||
platforms: [
|
||||
.iOS(.v9)
|
||||
],
|
||||
products: [
|
||||
.library(name: "CircleMenu",
|
||||
targets: ["CircleMenu"])
|
||||
],
|
||||
targets: [
|
||||
.target(name: "CircleMenu",
|
||||
path: "CircleMenuLib")
|
||||
],
|
||||
swiftLanguageVersions: [.v5]
|
||||
)
|
||||
@@ -1,7 +1,27 @@
|
||||

|
||||

|
||||
<a href="https://www.ramotion.com/agency/app-development/?utm_source=gthb&utm_medium=repo&utm_campaign=circle-menu"><img src="https://github.com/Ramotion/circle-menu/blob/master/header.png"></a>
|
||||
|
||||
<a href="https://github.com/Ramotion/circle-menu">
|
||||
<img align="left" src="https://github.com/Ramotion/circle-menu/blob/master/circle-menu.gif" width="480" height="360" /></a>
|
||||
|
||||
<p><h1 align="left">CIRCLE MENU</h1></p>
|
||||
|
||||
<h4>Simple, elegant UI menu with a circular layout and material design animations</h4>
|
||||
|
||||
|
||||
___
|
||||
|
||||
|
||||
|
||||
<p><h6>We specialize in the designing and coding of custom UI for Mobile Apps and Websites.</h6>
|
||||
<a href="https://www.ramotion.com/agency/app-development/?utm_source=gthb&utm_medium=repo&utm_campaign=circle-menu">
|
||||
<img src="https://github.com/ramotion/gliding-collection/raw/master/contact_our_team@2x.png" width="187" height="34"></a>
|
||||
</p>
|
||||
<p><h6>Stay tuned for the latest updates:</h6>
|
||||
<a href="https://goo.gl/rPFpid" >
|
||||
<img src="https://i.imgur.com/ziSqeSo.png/" width="156" height="28"></a></p>
|
||||
|
||||
</br>
|
||||
|
||||
# CircleMenu
|
||||
[](http://twitter.com/Ramotion)
|
||||
[](https://cocoapods.org/pods/CircleMenu)
|
||||
[](http://cocoapods.org/pods/CircleMenu)
|
||||
@@ -9,28 +29,13 @@
|
||||
[](https://github.com/Ramotion/circle-menu)
|
||||
[](https://codebeat.co/projects/github-com-ramotion-circle-menu)
|
||||
[](https://travis-ci.org/Ramotion/circle-menu)
|
||||
[](https://paypal.me/Ramotion)
|
||||
|
||||
## About
|
||||
This project is maintained by Ramotion, Inc.<br>
|
||||
We specialize in the designing and coding of custom UI for Mobile Apps and Websites.<br>
|
||||
|
||||
**Looking for developers for your project?**<br>
|
||||
This project is maintained by Ramotion, Inc. We specialize in the designing and coding of custom UI for Mobile Apps and Websites.
|
||||
|
||||
<a href="https://ramotion.com/?utm_source=gthb&utm_medium=special&utm_campaign=circle-menu-contact-us/#Get_in_Touch">
|
||||
<img src="https://github.com/ramotion/gliding-collection/raw/master/contact_our_team@2x.png" width="187" height="34"></a> <br>
|
||||
|
||||
|
||||
The [iPhone mockup](https://store.ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=circle-menu) available [here](https://store.ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=circle-menu).
|
||||
|
||||
## Try this UI control in action
|
||||
|
||||
<a href="https://itunes.apple.com/app/apple-store/id1182360240?pt=550053&ct=gthb-circle-menu&mt=8" > <img src="https://github.com/Ramotion/navigation-stack/raw/master/Download_on_the_App_Store_Badge_US-UK_135x40.png" width="170" height="58"></a>
|
||||
|
||||
## Requirements
|
||||
|
||||
- iOS 9.0+
|
||||
- Xcode 7.3
|
||||
- Xcode 9.0.1
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -39,8 +44,7 @@ Just add CircleMenuLib folder to your project.
|
||||
or use [CocoaPods](https://cocoapods.org) with Podfile:
|
||||
|
||||
```ruby
|
||||
pod 'CircleMenu', '~> 2.0.1' swift 3
|
||||
pod 'CircleMenu', '~> 1.0.7' swift 2
|
||||
pod 'CircleMenu'
|
||||
```
|
||||
or [Carthage](https://github.com/Carthage/Carthage) users can simply add to their `Cartfile`:
|
||||
```
|
||||
@@ -61,7 +65,7 @@ github "Ramotion/circle-menu"
|
||||
func circleMenu(circleMenu: CircleMenu, willDisplay button: UIButton, atIndex: Int)
|
||||
```
|
||||
|
||||
4) Use properties to confiure CircleMenu
|
||||
4) Use properties to configure CircleMenu
|
||||
|
||||
```swift
|
||||
@IBInspectable var buttonsCount: Int = 3
|
||||
@@ -96,26 +100,36 @@ optional func circleMenu(circleMenu: CircleMenu, buttonWillSelected button: UIBu
|
||||
// call after animation
|
||||
optional func circleMenu(circleMenu: CircleMenu, buttonDidSelected button: UIButton, atIndex: Int)
|
||||
|
||||
// call upon cancel of the menu
|
||||
// call upon cancel of the menu - fires immediately on button press
|
||||
optional func menuCollapsed(circleMenu: CircleMenu)
|
||||
|
||||
// call upon opening of the menu - fires immediately on button press
|
||||
optional func menuOpened(circleMenu: CircleMenu)
|
||||
```
|
||||
|
||||
## Licence
|
||||
## 🗂 Check this library on other language:
|
||||
<a href="https://github.com/Ramotion/circle-menu-android">
|
||||
<img src="https://github.com/ramotion/navigation-stack/raw/master/Android_Java@2x.png" width="178" height="81"></a>
|
||||
<a href="https://github.com/Ramotion/react-native-circle-menu">
|
||||
<img src="https://github.com/ramotion/navigation-stack/raw/master/React Native@2x.png" width="178" height="81"></a>
|
||||
|
||||
Circle menu is released under the MIT license.
|
||||
|
||||
## 📄 License
|
||||
|
||||
Circle Menu is released under the MIT license.
|
||||
See [LICENSE](./LICENSE) for details.
|
||||
<br>
|
||||
|
||||
# Get the Showroom App for iOS to give it a try
|
||||
This library is a part of a <a href="https://github.com/Ramotion/swift-ui-animation-components-and-libraries"><b>selection of our best UI open-source projects.</b></a>
|
||||
|
||||
If you use the open-source library in your project, please make sure to credit and backlink to www.ramotion.com
|
||||
|
||||
## 📱 Get the Showroom App for iOS to give it a try
|
||||
Try this UI component and more like this in our iOS app. Contact us if interested.
|
||||
|
||||
<a href="https://itunes.apple.com/app/apple-store/id1182360240?pt=550053&ct=circle-menu&mt=8" >
|
||||
<a href="https://itunes.apple.com/app/apple-store/id1182360240?pt=550053&ct=folding-cell&mt=8" >
|
||||
<img src="https://github.com/ramotion/gliding-collection/raw/master/app_store@2x.png" width="117" height="34"></a>
|
||||
<a href="https://ramotion.com/?utm_source=gthb&utm_medium=special&utm_campaign=circle-menu-contact-us/#Get_in_Touch">
|
||||
|
||||
<a href="https://www.ramotion.com/agency/app-development/?utm_source=gthb&utm_medium=repo&utm_campaign=circle-menu">
|
||||
<img src="https://github.com/ramotion/gliding-collection/raw/master/contact_our_team@2x.png" width="187" height="34"></a>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
Follow us for the latest updates<br>
|
||||
[](https://twitter.com/intent/tweet?text=https://github.com/ramotion/circle-menu)
|
||||
[](https://twitter.com/ramotion)
|
||||
|
||||
|
After Width: | Height: | Size: 3.2 MiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 1.3 MiB |