diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bce6af --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +xcuserdata diff --git a/RotatingWheelController.xcodeproj/project.pbxproj b/RotatingWheelController.xcodeproj/project.pbxproj new file mode 100644 index 0000000..dbbb30e --- /dev/null +++ b/RotatingWheelController.xcodeproj/project.pbxproj @@ -0,0 +1,365 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + E216819721993B210025B547 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E216819621993B210025B547 /* AppDelegate.swift */; }; + E216819921993B210025B547 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E216819821993B210025B547 /* ViewController.swift */; }; + E216819C21993B210025B547 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E216819A21993B210025B547 /* Main.storyboard */; }; + E216819E21993B210025B547 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E216819D21993B210025B547 /* Assets.xcassets */; }; + E21681A121993B210025B547 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E216819F21993B210025B547 /* LaunchScreen.storyboard */; }; + E21681A921993BA60025B547 /* SMRotaryWheel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E21681A821993BA60025B547 /* SMRotaryWheel.swift */; }; + E21681AB21993BC40025B547 /* SMRotaryProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = E21681AA21993BC40025B547 /* SMRotaryProtocol.swift */; }; + E21681AE219940140025B547 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E21681AD219940140025B547 /* QuartzCore.framework */; }; + E21681B02199478E0025B547 /* SMSector.swift in Sources */ = {isa = PBXBuildFile; fileRef = E21681AF2199478E0025B547 /* SMSector.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + E216819321993B210025B547 /* RotatingWheelController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RotatingWheelController.app; sourceTree = BUILT_PRODUCTS_DIR; }; + E216819621993B210025B547 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + E216819821993B210025B547 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + E216819B21993B210025B547 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + E216819D21993B210025B547 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + E21681A021993B210025B547 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + E21681A221993B210025B547 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + E21681A821993BA60025B547 /* SMRotaryWheel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SMRotaryWheel.swift; sourceTree = ""; }; + E21681AA21993BC40025B547 /* SMRotaryProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SMRotaryProtocol.swift; sourceTree = ""; }; + E21681AD219940140025B547 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; + E21681AF2199478E0025B547 /* SMSector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SMSector.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + E216819021993B210025B547 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + E21681AE219940140025B547 /* QuartzCore.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + E216818A21993B210025B547 = { + isa = PBXGroup; + children = ( + E21681AF2199478E0025B547 /* SMSector.swift */, + E21681A821993BA60025B547 /* SMRotaryWheel.swift */, + E21681AA21993BC40025B547 /* SMRotaryProtocol.swift */, + E216819521993B210025B547 /* RotatingWheelController */, + E216819421993B210025B547 /* Products */, + E21681AC219940140025B547 /* Frameworks */, + ); + sourceTree = ""; + }; + E216819421993B210025B547 /* Products */ = { + isa = PBXGroup; + children = ( + E216819321993B210025B547 /* RotatingWheelController.app */, + ); + name = Products; + sourceTree = ""; + }; + E216819521993B210025B547 /* RotatingWheelController */ = { + isa = PBXGroup; + children = ( + E216819621993B210025B547 /* AppDelegate.swift */, + E216819821993B210025B547 /* ViewController.swift */, + E216819A21993B210025B547 /* Main.storyboard */, + E216819D21993B210025B547 /* Assets.xcassets */, + E216819F21993B210025B547 /* LaunchScreen.storyboard */, + E21681A221993B210025B547 /* Info.plist */, + ); + path = RotatingWheelController; + sourceTree = ""; + }; + E21681AC219940140025B547 /* Frameworks */ = { + isa = PBXGroup; + children = ( + E21681AD219940140025B547 /* QuartzCore.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + E216819221993B210025B547 /* RotatingWheelController */ = { + isa = PBXNativeTarget; + buildConfigurationList = E21681A521993B210025B547 /* Build configuration list for PBXNativeTarget "RotatingWheelController" */; + buildPhases = ( + E216818F21993B210025B547 /* Sources */, + E216819021993B210025B547 /* Frameworks */, + E216819121993B210025B547 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = RotatingWheelController; + productName = RotatingWheelController; + productReference = E216819321993B210025B547 /* RotatingWheelController.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + E216818B21993B210025B547 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1010; + LastUpgradeCheck = 1010; + ORGANIZATIONNAME = tom; + TargetAttributes = { + E216819221993B210025B547 = { + CreatedOnToolsVersion = 10.1; + }; + }; + }; + buildConfigurationList = E216818E21993B210025B547 /* Build configuration list for PBXProject "RotatingWheelController" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = E216818A21993B210025B547; + productRefGroup = E216819421993B210025B547 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + E216819221993B210025B547 /* RotatingWheelController */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + E216819121993B210025B547 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E21681A121993B210025B547 /* LaunchScreen.storyboard in Resources */, + E216819E21993B210025B547 /* Assets.xcassets in Resources */, + E216819C21993B210025B547 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + E216818F21993B210025B547 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E21681AB21993BC40025B547 /* SMRotaryProtocol.swift in Sources */, + E21681A921993BA60025B547 /* SMRotaryWheel.swift in Sources */, + E216819921993B210025B547 /* ViewController.swift in Sources */, + E216819721993B210025B547 /* AppDelegate.swift in Sources */, + E21681B02199478E0025B547 /* SMSector.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + E216819A21993B210025B547 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + E216819B21993B210025B547 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + E216819F21993B210025B547 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + E21681A021993B210025B547 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + E21681A321993B210025B547 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = 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_DOCUMENTATION_COMMENTS = YES; + 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_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.1; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + E21681A421993B210025B547 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = 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_DOCUMENTATION_COMMENTS = YES; + 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_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.1; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + E21681A621993B210025B547 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 3Y63MCQ957; + INFOPLIST_FILE = RotatingWheelController/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = au.com.msbit.RotatingWheelController; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.2; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + E21681A721993B210025B547 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 3Y63MCQ957; + INFOPLIST_FILE = RotatingWheelController/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = au.com.msbit.RotatingWheelController; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.2; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + E216818E21993B210025B547 /* Build configuration list for PBXProject "RotatingWheelController" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E21681A321993B210025B547 /* Debug */, + E21681A421993B210025B547 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + E21681A521993B210025B547 /* Build configuration list for PBXNativeTarget "RotatingWheelController" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E21681A621993B210025B547 /* Debug */, + E21681A721993B210025B547 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = E216818B21993B210025B547 /* Project object */; +} diff --git a/RotatingWheelController.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/RotatingWheelController.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ac5c357 --- /dev/null +++ b/RotatingWheelController.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/RotatingWheelController.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/RotatingWheelController.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/RotatingWheelController.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/RotatingWheelController/AppDelegate.swift b/RotatingWheelController/AppDelegate.swift new file mode 100644 index 0000000..dc13079 --- /dev/null +++ b/RotatingWheelController/AppDelegate.swift @@ -0,0 +1,46 @@ +// +// AppDelegate.swift +// RotatingWheelController +// +// Created by tom on 12/11/18. +// Copyright © 2018 tom. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + func applicationWillResignActive(_ application: UIApplication) { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(_ application: UIApplication) { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + } + + func applicationWillEnterForeground(_ application: UIApplication) { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(_ application: UIApplication) { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + func applicationWillTerminate(_ application: UIApplication) { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } + + +} + diff --git a/RotatingWheelController/Assets.xcassets/AppIcon.appiconset/Contents.json b/RotatingWheelController/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d8db8d6 --- /dev/null +++ b/RotatingWheelController/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/RotatingWheelController/Assets.xcassets/Contents.json b/RotatingWheelController/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/RotatingWheelController/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/RotatingWheelController/Base.lproj/LaunchScreen.storyboard b/RotatingWheelController/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..bfa3612 --- /dev/null +++ b/RotatingWheelController/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RotatingWheelController/Base.lproj/Main.storyboard b/RotatingWheelController/Base.lproj/Main.storyboard new file mode 100644 index 0000000..f1bcf38 --- /dev/null +++ b/RotatingWheelController/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RotatingWheelController/Info.plist b/RotatingWheelController/Info.plist new file mode 100644 index 0000000..16be3b6 --- /dev/null +++ b/RotatingWheelController/Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/RotatingWheelController/ViewController.swift b/RotatingWheelController/ViewController.swift new file mode 100644 index 0000000..0d32bc4 --- /dev/null +++ b/RotatingWheelController/ViewController.swift @@ -0,0 +1,25 @@ +// +// ViewController.swift +// RotatingWheelController +// +// Created by tom on 12/11/18. +// Copyright © 2018 tom. All rights reserved. +// + +import os +import UIKit + +class ViewController: UIViewController, SMRotaryProtocol { + func wheelDidChangeValue(to: Int) { + os_log(OSLogType.default, "%d", to); + } + + override func viewDidLoad() { + super.viewDidLoad() + let wheel = SMRotaryWheel(frame: view.frame, delegate: self, numberOfSections: 3) + view.addSubview(wheel) + } + + +} + diff --git a/SMRotaryProtocol.swift b/SMRotaryProtocol.swift new file mode 100644 index 0000000..719f094 --- /dev/null +++ b/SMRotaryProtocol.swift @@ -0,0 +1,11 @@ +// +// SMRotaryProtocol.swift +// RotatingWheelController +// +// Created by tom on 12/11/18. +// Copyright © 2018 tom. All rights reserved. +// + +protocol SMRotaryProtocol { + func wheelDidChangeValue(to: Int) +} diff --git a/SMRotaryWheel.swift b/SMRotaryWheel.swift new file mode 100644 index 0000000..3c6f8b3 --- /dev/null +++ b/SMRotaryWheel.swift @@ -0,0 +1,132 @@ +// +// SMRotaryWheel.swift +// RotatingWheelController +// +// Created by tom on 12/11/18. +// Copyright © 2018 tom. All rights reserved. +// + +import UIKit + +class SMRotaryWheel: UIControl { + var delegate: SMRotaryProtocol? + var container: UIView? + var numberOfSections: Int? + var startTransform = CGAffineTransform.identity + var deltaAngle: CGFloat? + var sectors: [SMSector] = [] + var currentSector: Int = 0 + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + init(frame: CGRect, delegate: SMRotaryProtocol, numberOfSections: Int) { + super.init(frame: frame) + self.delegate = delegate + self.numberOfSections = numberOfSections + self.setup() + } + + override func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool { + let touchPoint = touch.location(in: self) + let dist = calculateDistanceFromCentre(point: touchPoint) + if dist < 40 || dist > 400 { + return false + } + guard let container = container else { + return false + } + + let dx = touchPoint.x - container.center.x + let dy = touchPoint.y - container.center.y + deltaAngle = atan2(dy, dx) + startTransform = container.transform + + return true + } + + override func continueTracking(_ touch: UITouch, with event: UIEvent?) -> Bool { + guard let container = container, let deltaAngle = deltaAngle else { + return false + } + + let touchPoint = touch.location(in: self) + let dx = touchPoint.x - container.center.x + let dy = touchPoint.y - container.center.y + let angle = atan2(dy, dx) + let angleDifference = deltaAngle - angle + container.transform = startTransform.rotated(by: -angleDifference) + + return true + } + + override func endTracking(_ touch: UITouch?, with event: UIEvent?) { + guard let container = container else { + return + } + + let transformAngle = atan2(container.transform.b, container.transform.a) + guard let sector = sectors.first(where: {$0.contains(transformAngle)}) else { + return + } + + let newVal = CGFloat(transformAngle - sector.middle) + currentSector = sector.value + UIView.beginAnimations(nil, context: nil) + UIView.setAnimationDuration(0.2) + container.transform = container.transform.rotated(by: -newVal) + UIView.commitAnimations() + + delegate?.wheelDidChangeValue(to: currentSector) + } + + func calculateDistanceFromCentre(point: CGPoint) -> CGFloat { + let centre = CGPoint(x: bounds.size.width / 2, y: bounds.size.height / 2) + let dx = point.x - centre.x + let dy = point.y - centre.y + return (dx * dx + dy * dy).squareRoot() + } + + func setup() { + container = UIView(frame: frame) + guard let container = container, let numberOfSections = numberOfSections else { + return + } + + let sectorAngle = 2 * CGFloat.pi / CGFloat(numberOfSections) + var upper = sectorAngle / 2.0 + + for i in 0..(lower: -upper, upper: upper, value: i)) + upper = -upper + } else { + sectors.append(SMSector(lower: lower, upper: upper, value: i)) + upper = lower + } + } + + container.isUserInteractionEnabled = false + addSubview(container) + + delegate?.wheelDidChangeValue(to: currentSector) + } +} diff --git a/SMSector.swift b/SMSector.swift new file mode 100644 index 0000000..621bf27 --- /dev/null +++ b/SMSector.swift @@ -0,0 +1,34 @@ +// +// SMSector.swift +// RotatingWheelController +// +// Created by tom on 12/11/18. +// Copyright © 2018 tom. All rights reserved. +// + +import UIKit + +class SMSector { + var lower: CGFloat + var upper: CGFloat + var value: T + var middle: CGFloat { + get { + if lower < upper { + return (lower + upper) / 2.0 + } else { + return CGFloat.pi + } + } + } + + init(lower: CGFloat, upper: CGFloat, value: T) { + self.lower = lower + self.upper = upper + self.value = value + } + + func contains(_ element: CGFloat) -> Bool { + return lower < upper ? lower <= element && element < upper : lower <= element || element < upper + } +}