├── .gitignore ├── LICENSE ├── README.md ├── Untitled.gif └── WLBallView ├── WLBallView.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── WLBallView ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── ViewController.h ├── ViewController.m ├── WLMotionView ├── WLBallTool.h ├── WLBallTool.m ├── WLBallView.h └── WLBallView.m ├── main.m ├── 大师球.png ├── 精灵球.png ├── 超级球.png └── 高级球.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | # Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots 56 | fastlane/test_output 57 | 58 | # Code Injection 59 | # 60 | # After new code Injection tools there's a generated folder /iOSInjectionProject 61 | # https://github.com/johnno1962/injectionforxcode 62 | 63 | iOSInjectionProject/ 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 wangliu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WLBallView 2 | OC - 物理仿真行为(小球滚动) 3 | 4 | 原理解析博文地址: 5 | http://www.jianshu.com/p/883d042178fa 6 | 7 | ![image](https://raw.githubusercontent.com/wangliujiayou/WLBallView/master/Untitled.gif) 8 | 9 | ## 框架使用 10 | 1.导入 `#import "WLBallView.h"` 11 | 12 | 2.创建`WLBallView`控件 13 | 14 | 3.调用`WLBallView`方法即可实现 15 | 16 | ``` 17 | // 创建控件 18 | WLBallView * ballView = [[WLBallView alloc] initWithFrame:CGRectMake(0, 80, 50, 50) AndImageName:self.array[arc4random_uniform(4)]]; 19 | // 添加父视图(边界视图) 20 | [self.view addSubview:ballView]; 21 | // 开始执行 22 | [ballView starMotion]; 23 | ``` 24 | -------------------------------------------------------------------------------- /Untitled.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coderLiuW/WLBallView/700686e4175bd976aaf9fe7a7d91f310c79f9f5a/Untitled.gif -------------------------------------------------------------------------------- /WLBallView/WLBallView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C3CA9B8A1EF3C0130072F1E1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C3CA9B891EF3C0130072F1E1 /* main.m */; }; 11 | C3CA9B8D1EF3C0130072F1E1 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C3CA9B8C1EF3C0130072F1E1 /* AppDelegate.m */; }; 12 | C3CA9B901EF3C0130072F1E1 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C3CA9B8F1EF3C0130072F1E1 /* ViewController.m */; }; 13 | C3CA9B931EF3C0130072F1E1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C3CA9B911EF3C0130072F1E1 /* Main.storyboard */; }; 14 | C3CA9B951EF3C0130072F1E1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C3CA9B941EF3C0130072F1E1 /* Assets.xcassets */; }; 15 | C3CA9B981EF3C0130072F1E1 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C3CA9B961EF3C0130072F1E1 /* LaunchScreen.storyboard */; }; 16 | C3CA9BA41EF3C3540072F1E1 /* WLBallView.m in Sources */ = {isa = PBXBuildFile; fileRef = C3CA9BA11EF3C3540072F1E1 /* WLBallView.m */; }; 17 | C3CA9BA51EF3C3540072F1E1 /* WLBallTool.m in Sources */ = {isa = PBXBuildFile; fileRef = C3CA9BA31EF3C3540072F1E1 /* WLBallTool.m */; }; 18 | C3CA9BAA1EF3C3AE0072F1E1 /* 大师球.png in Resources */ = {isa = PBXBuildFile; fileRef = C3CA9BA61EF3C3AE0072F1E1 /* 大师球.png */; }; 19 | C3CA9BAB1EF3C3AE0072F1E1 /* 超级球.png in Resources */ = {isa = PBXBuildFile; fileRef = C3CA9BA71EF3C3AE0072F1E1 /* 超级球.png */; }; 20 | C3CA9BAC1EF3C3AE0072F1E1 /* 高级球.png in Resources */ = {isa = PBXBuildFile; fileRef = C3CA9BA81EF3C3AE0072F1E1 /* 高级球.png */; }; 21 | C3CA9BAD1EF3C3AE0072F1E1 /* 精灵球.png in Resources */ = {isa = PBXBuildFile; fileRef = C3CA9BA91EF3C3AE0072F1E1 /* 精灵球.png */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXFileReference section */ 25 | C3CA9B851EF3C0130072F1E1 /* WLBallView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WLBallView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 26 | C3CA9B891EF3C0130072F1E1 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 27 | C3CA9B8B1EF3C0130072F1E1 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 28 | C3CA9B8C1EF3C0130072F1E1 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 29 | C3CA9B8E1EF3C0130072F1E1 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 30 | C3CA9B8F1EF3C0130072F1E1 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 31 | C3CA9B921EF3C0130072F1E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 32 | C3CA9B941EF3C0130072F1E1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 33 | C3CA9B971EF3C0130072F1E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 34 | C3CA9B991EF3C0130072F1E1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | C3CA9BA01EF3C3540072F1E1 /* WLBallView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WLBallView.h; sourceTree = ""; }; 36 | C3CA9BA11EF3C3540072F1E1 /* WLBallView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WLBallView.m; sourceTree = ""; }; 37 | C3CA9BA21EF3C3540072F1E1 /* WLBallTool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WLBallTool.h; sourceTree = ""; }; 38 | C3CA9BA31EF3C3540072F1E1 /* WLBallTool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WLBallTool.m; sourceTree = ""; }; 39 | C3CA9BA61EF3C3AE0072F1E1 /* 大师球.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "大师球.png"; sourceTree = ""; }; 40 | C3CA9BA71EF3C3AE0072F1E1 /* 超级球.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "超级球.png"; sourceTree = ""; }; 41 | C3CA9BA81EF3C3AE0072F1E1 /* 高级球.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "高级球.png"; sourceTree = ""; }; 42 | C3CA9BA91EF3C3AE0072F1E1 /* 精灵球.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "精灵球.png"; sourceTree = ""; }; 43 | /* End PBXFileReference section */ 44 | 45 | /* Begin PBXFrameworksBuildPhase section */ 46 | C3CA9B821EF3C0130072F1E1 /* Frameworks */ = { 47 | isa = PBXFrameworksBuildPhase; 48 | buildActionMask = 2147483647; 49 | files = ( 50 | ); 51 | runOnlyForDeploymentPostprocessing = 0; 52 | }; 53 | /* End PBXFrameworksBuildPhase section */ 54 | 55 | /* Begin PBXGroup section */ 56 | C3CA9B7C1EF3C0130072F1E1 = { 57 | isa = PBXGroup; 58 | children = ( 59 | C3CA9B871EF3C0130072F1E1 /* WLBallView */, 60 | C3CA9B861EF3C0130072F1E1 /* Products */, 61 | ); 62 | sourceTree = ""; 63 | }; 64 | C3CA9B861EF3C0130072F1E1 /* Products */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | C3CA9B851EF3C0130072F1E1 /* WLBallView.app */, 68 | ); 69 | name = Products; 70 | sourceTree = ""; 71 | }; 72 | C3CA9B871EF3C0130072F1E1 /* WLBallView */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | C3CA9B9F1EF3C3460072F1E1 /* WLMotionView */, 76 | C3CA9B8B1EF3C0130072F1E1 /* AppDelegate.h */, 77 | C3CA9B8C1EF3C0130072F1E1 /* AppDelegate.m */, 78 | C3CA9B8E1EF3C0130072F1E1 /* ViewController.h */, 79 | C3CA9B8F1EF3C0130072F1E1 /* ViewController.m */, 80 | C3CA9B911EF3C0130072F1E1 /* Main.storyboard */, 81 | C3CA9BA61EF3C3AE0072F1E1 /* 大师球.png */, 82 | C3CA9BA71EF3C3AE0072F1E1 /* 超级球.png */, 83 | C3CA9BA81EF3C3AE0072F1E1 /* 高级球.png */, 84 | C3CA9BA91EF3C3AE0072F1E1 /* 精灵球.png */, 85 | C3CA9B941EF3C0130072F1E1 /* Assets.xcassets */, 86 | C3CA9B961EF3C0130072F1E1 /* LaunchScreen.storyboard */, 87 | C3CA9B991EF3C0130072F1E1 /* Info.plist */, 88 | C3CA9B881EF3C0130072F1E1 /* Supporting Files */, 89 | ); 90 | path = WLBallView; 91 | sourceTree = ""; 92 | }; 93 | C3CA9B881EF3C0130072F1E1 /* Supporting Files */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | C3CA9B891EF3C0130072F1E1 /* main.m */, 97 | ); 98 | name = "Supporting Files"; 99 | sourceTree = ""; 100 | }; 101 | C3CA9B9F1EF3C3460072F1E1 /* WLMotionView */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | C3CA9BA01EF3C3540072F1E1 /* WLBallView.h */, 105 | C3CA9BA11EF3C3540072F1E1 /* WLBallView.m */, 106 | C3CA9BA21EF3C3540072F1E1 /* WLBallTool.h */, 107 | C3CA9BA31EF3C3540072F1E1 /* WLBallTool.m */, 108 | ); 109 | path = WLMotionView; 110 | sourceTree = ""; 111 | }; 112 | /* End PBXGroup section */ 113 | 114 | /* Begin PBXNativeTarget section */ 115 | C3CA9B841EF3C0130072F1E1 /* WLBallView */ = { 116 | isa = PBXNativeTarget; 117 | buildConfigurationList = C3CA9B9C1EF3C0130072F1E1 /* Build configuration list for PBXNativeTarget "WLBallView" */; 118 | buildPhases = ( 119 | C3CA9B811EF3C0130072F1E1 /* Sources */, 120 | C3CA9B821EF3C0130072F1E1 /* Frameworks */, 121 | C3CA9B831EF3C0130072F1E1 /* Resources */, 122 | ); 123 | buildRules = ( 124 | ); 125 | dependencies = ( 126 | ); 127 | name = WLBallView; 128 | productName = WLBallView; 129 | productReference = C3CA9B851EF3C0130072F1E1 /* WLBallView.app */; 130 | productType = "com.apple.product-type.application"; 131 | }; 132 | /* End PBXNativeTarget section */ 133 | 134 | /* Begin PBXProject section */ 135 | C3CA9B7D1EF3C0130072F1E1 /* Project object */ = { 136 | isa = PBXProject; 137 | attributes = { 138 | LastUpgradeCheck = 0830; 139 | ORGANIZATIONNAME = WL; 140 | TargetAttributes = { 141 | C3CA9B841EF3C0130072F1E1 = { 142 | CreatedOnToolsVersion = 8.3.2; 143 | DevelopmentTeam = AB3B393359; 144 | ProvisioningStyle = Automatic; 145 | }; 146 | }; 147 | }; 148 | buildConfigurationList = C3CA9B801EF3C0130072F1E1 /* Build configuration list for PBXProject "WLBallView" */; 149 | compatibilityVersion = "Xcode 3.2"; 150 | developmentRegion = English; 151 | hasScannedForEncodings = 0; 152 | knownRegions = ( 153 | en, 154 | Base, 155 | ); 156 | mainGroup = C3CA9B7C1EF3C0130072F1E1; 157 | productRefGroup = C3CA9B861EF3C0130072F1E1 /* Products */; 158 | projectDirPath = ""; 159 | projectRoot = ""; 160 | targets = ( 161 | C3CA9B841EF3C0130072F1E1 /* WLBallView */, 162 | ); 163 | }; 164 | /* End PBXProject section */ 165 | 166 | /* Begin PBXResourcesBuildPhase section */ 167 | C3CA9B831EF3C0130072F1E1 /* Resources */ = { 168 | isa = PBXResourcesBuildPhase; 169 | buildActionMask = 2147483647; 170 | files = ( 171 | C3CA9BAC1EF3C3AE0072F1E1 /* 高级球.png in Resources */, 172 | C3CA9BAA1EF3C3AE0072F1E1 /* 大师球.png in Resources */, 173 | C3CA9B981EF3C0130072F1E1 /* LaunchScreen.storyboard in Resources */, 174 | C3CA9B951EF3C0130072F1E1 /* Assets.xcassets in Resources */, 175 | C3CA9B931EF3C0130072F1E1 /* Main.storyboard in Resources */, 176 | C3CA9BAB1EF3C3AE0072F1E1 /* 超级球.png in Resources */, 177 | C3CA9BAD1EF3C3AE0072F1E1 /* 精灵球.png in Resources */, 178 | ); 179 | runOnlyForDeploymentPostprocessing = 0; 180 | }; 181 | /* End PBXResourcesBuildPhase section */ 182 | 183 | /* Begin PBXSourcesBuildPhase section */ 184 | C3CA9B811EF3C0130072F1E1 /* Sources */ = { 185 | isa = PBXSourcesBuildPhase; 186 | buildActionMask = 2147483647; 187 | files = ( 188 | C3CA9BA41EF3C3540072F1E1 /* WLBallView.m in Sources */, 189 | C3CA9B901EF3C0130072F1E1 /* ViewController.m in Sources */, 190 | C3CA9BA51EF3C3540072F1E1 /* WLBallTool.m in Sources */, 191 | C3CA9B8D1EF3C0130072F1E1 /* AppDelegate.m in Sources */, 192 | C3CA9B8A1EF3C0130072F1E1 /* main.m in Sources */, 193 | ); 194 | runOnlyForDeploymentPostprocessing = 0; 195 | }; 196 | /* End PBXSourcesBuildPhase section */ 197 | 198 | /* Begin PBXVariantGroup section */ 199 | C3CA9B911EF3C0130072F1E1 /* Main.storyboard */ = { 200 | isa = PBXVariantGroup; 201 | children = ( 202 | C3CA9B921EF3C0130072F1E1 /* Base */, 203 | ); 204 | name = Main.storyboard; 205 | sourceTree = ""; 206 | }; 207 | C3CA9B961EF3C0130072F1E1 /* LaunchScreen.storyboard */ = { 208 | isa = PBXVariantGroup; 209 | children = ( 210 | C3CA9B971EF3C0130072F1E1 /* Base */, 211 | ); 212 | name = LaunchScreen.storyboard; 213 | sourceTree = ""; 214 | }; 215 | /* End PBXVariantGroup section */ 216 | 217 | /* Begin XCBuildConfiguration section */ 218 | C3CA9B9A1EF3C0130072F1E1 /* Debug */ = { 219 | isa = XCBuildConfiguration; 220 | buildSettings = { 221 | ALWAYS_SEARCH_USER_PATHS = NO; 222 | CLANG_ANALYZER_NONNULL = YES; 223 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 224 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 225 | CLANG_CXX_LIBRARY = "libc++"; 226 | CLANG_ENABLE_MODULES = YES; 227 | CLANG_ENABLE_OBJC_ARC = YES; 228 | CLANG_WARN_BOOL_CONVERSION = YES; 229 | CLANG_WARN_CONSTANT_CONVERSION = YES; 230 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 231 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 232 | CLANG_WARN_EMPTY_BODY = YES; 233 | CLANG_WARN_ENUM_CONVERSION = YES; 234 | CLANG_WARN_INFINITE_RECURSION = YES; 235 | CLANG_WARN_INT_CONVERSION = YES; 236 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 237 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 238 | CLANG_WARN_UNREACHABLE_CODE = YES; 239 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 240 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 241 | COPY_PHASE_STRIP = NO; 242 | DEBUG_INFORMATION_FORMAT = dwarf; 243 | ENABLE_STRICT_OBJC_MSGSEND = YES; 244 | ENABLE_TESTABILITY = YES; 245 | GCC_C_LANGUAGE_STANDARD = gnu99; 246 | GCC_DYNAMIC_NO_PIC = NO; 247 | GCC_NO_COMMON_BLOCKS = YES; 248 | GCC_OPTIMIZATION_LEVEL = 0; 249 | GCC_PREPROCESSOR_DEFINITIONS = ( 250 | "DEBUG=1", 251 | "$(inherited)", 252 | ); 253 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 254 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 255 | GCC_WARN_UNDECLARED_SELECTOR = YES; 256 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 257 | GCC_WARN_UNUSED_FUNCTION = YES; 258 | GCC_WARN_UNUSED_VARIABLE = YES; 259 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 260 | MTL_ENABLE_DEBUG_INFO = YES; 261 | ONLY_ACTIVE_ARCH = YES; 262 | SDKROOT = iphoneos; 263 | }; 264 | name = Debug; 265 | }; 266 | C3CA9B9B1EF3C0130072F1E1 /* Release */ = { 267 | isa = XCBuildConfiguration; 268 | buildSettings = { 269 | ALWAYS_SEARCH_USER_PATHS = NO; 270 | CLANG_ANALYZER_NONNULL = YES; 271 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 272 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 273 | CLANG_CXX_LIBRARY = "libc++"; 274 | CLANG_ENABLE_MODULES = YES; 275 | CLANG_ENABLE_OBJC_ARC = YES; 276 | CLANG_WARN_BOOL_CONVERSION = YES; 277 | CLANG_WARN_CONSTANT_CONVERSION = YES; 278 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 279 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 280 | CLANG_WARN_EMPTY_BODY = YES; 281 | CLANG_WARN_ENUM_CONVERSION = YES; 282 | CLANG_WARN_INFINITE_RECURSION = YES; 283 | CLANG_WARN_INT_CONVERSION = YES; 284 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 285 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 286 | CLANG_WARN_UNREACHABLE_CODE = YES; 287 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 288 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 289 | COPY_PHASE_STRIP = NO; 290 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 291 | ENABLE_NS_ASSERTIONS = NO; 292 | ENABLE_STRICT_OBJC_MSGSEND = YES; 293 | GCC_C_LANGUAGE_STANDARD = gnu99; 294 | GCC_NO_COMMON_BLOCKS = YES; 295 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 296 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 297 | GCC_WARN_UNDECLARED_SELECTOR = YES; 298 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 299 | GCC_WARN_UNUSED_FUNCTION = YES; 300 | GCC_WARN_UNUSED_VARIABLE = YES; 301 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 302 | MTL_ENABLE_DEBUG_INFO = NO; 303 | SDKROOT = iphoneos; 304 | VALIDATE_PRODUCT = YES; 305 | }; 306 | name = Release; 307 | }; 308 | C3CA9B9D1EF3C0130072F1E1 /* Debug */ = { 309 | isa = XCBuildConfiguration; 310 | buildSettings = { 311 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 312 | DEVELOPMENT_TEAM = AB3B393359; 313 | INFOPLIST_FILE = WLBallView/Info.plist; 314 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 315 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 316 | PRODUCT_BUNDLE_IDENTIFIER = com.wangliu.WLBallView; 317 | PRODUCT_NAME = "$(TARGET_NAME)"; 318 | }; 319 | name = Debug; 320 | }; 321 | C3CA9B9E1EF3C0130072F1E1 /* Release */ = { 322 | isa = XCBuildConfiguration; 323 | buildSettings = { 324 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 325 | DEVELOPMENT_TEAM = AB3B393359; 326 | INFOPLIST_FILE = WLBallView/Info.plist; 327 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 328 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 329 | PRODUCT_BUNDLE_IDENTIFIER = com.wangliu.WLBallView; 330 | PRODUCT_NAME = "$(TARGET_NAME)"; 331 | }; 332 | name = Release; 333 | }; 334 | /* End XCBuildConfiguration section */ 335 | 336 | /* Begin XCConfigurationList section */ 337 | C3CA9B801EF3C0130072F1E1 /* Build configuration list for PBXProject "WLBallView" */ = { 338 | isa = XCConfigurationList; 339 | buildConfigurations = ( 340 | C3CA9B9A1EF3C0130072F1E1 /* Debug */, 341 | C3CA9B9B1EF3C0130072F1E1 /* Release */, 342 | ); 343 | defaultConfigurationIsVisible = 0; 344 | defaultConfigurationName = Release; 345 | }; 346 | C3CA9B9C1EF3C0130072F1E1 /* Build configuration list for PBXNativeTarget "WLBallView" */ = { 347 | isa = XCConfigurationList; 348 | buildConfigurations = ( 349 | C3CA9B9D1EF3C0130072F1E1 /* Debug */, 350 | C3CA9B9E1EF3C0130072F1E1 /* Release */, 351 | ); 352 | defaultConfigurationIsVisible = 0; 353 | defaultConfigurationName = Release; 354 | }; 355 | /* End XCConfigurationList section */ 356 | }; 357 | rootObject = C3CA9B7D1EF3C0130072F1E1 /* Project object */; 358 | } 359 | -------------------------------------------------------------------------------- /WLBallView/WLBallView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /WLBallView/WLBallView/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // WLBallView 4 | // 5 | // Created by administrator on 2017/6/16. 6 | // Copyright © 2017年 WL. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /WLBallView/WLBallView/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // WLBallView 4 | // 5 | // Created by administrator on 2017/6/16. 6 | // Copyright © 2017年 WL. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // 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. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // 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. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // 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. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /WLBallView/WLBallView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /WLBallView/WLBallView/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /WLBallView/WLBallView/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /WLBallView/WLBallView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /WLBallView/WLBallView/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // WLBallView 4 | // 5 | // Created by administrator on 2017/6/16. 6 | // Copyright © 2017年 WL. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /WLBallView/WLBallView/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // WLBallView 4 | // 5 | // Created by administrator on 2017/6/16. 6 | // Copyright © 2017年 WL. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "WLBallView.h" 11 | #import "WLBallTool.h" 12 | 13 | @interface ViewController () 14 | 15 | @property (nonatomic, strong) NSArray * array; 16 | 17 | @end 18 | 19 | @implementation ViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | self.array = @[@"大师球",@"高级球",@"超级球",@"精灵球"]; 24 | } 25 | 26 | 27 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 28 | 29 | WLBallView * ballView = [[WLBallView alloc] initWithFrame:CGRectMake(0, 80, 50, 50) AndImageName:self.array[arc4random_uniform(4)]]; 30 | [self.view addSubview:ballView]; 31 | [ballView starMotion]; 32 | 33 | } 34 | 35 | - (void)viewDidDisappear:(BOOL)animated { 36 | 37 | [super viewDidDisappear:animated]; 38 | 39 | [[WLBallTool shareBallTool] stopMotionUpdates]; 40 | 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /WLBallView/WLBallView/WLMotionView/WLBallTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // WLBallTool.h 3 | // WLBallView 4 | // 5 | // Created by administrator on 2017/6/15. 6 | // Copyright © 2017年 WL. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WLBallTool : NSObject 12 | 13 | @property (nonatomic, weak) UIView * referenceView; 14 | 15 | + (instancetype)shareBallTool; 16 | 17 | - (void)addAimView:(UIView *)ballView referenceView:(UIView *)referenceView; 18 | 19 | - (void)stopMotionUpdates; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /WLBallView/WLBallView/WLMotionView/WLBallTool.m: -------------------------------------------------------------------------------- 1 | // 2 | // WLBallTool.m 3 | // WLBallView 4 | // 5 | // Created by administrator on 2017/6/15. 6 | // Copyright © 2017年 WL. All rights reserved. 7 | // 8 | 9 | #import "WLBallTool.h" 10 | #import 11 | 12 | @interface WLBallTool () 13 | 14 | @property (nonatomic, strong) CMMotionManager * manager; 15 | @property (nonatomic, strong) UIGravityBehavior * gravity; 16 | @property (nonatomic, strong) UIDynamicAnimator * animator; 17 | @property (nonatomic, strong) UICollisionBehavior * collision; 18 | @property (nonatomic, strong) UIDynamicItemBehavior * dynamic; 19 | 20 | @end 21 | 22 | 23 | 24 | @implementation WLBallTool 25 | 26 | static dispatch_once_t onceToken; 27 | 28 | + (instancetype)shareBallTool { 29 | 30 | static WLBallTool * ball; 31 | 32 | 33 | dispatch_once(&onceToken, ^{ 34 | 35 | ball = [[WLBallTool alloc] init]; 36 | 37 | }); 38 | 39 | return ball; 40 | } 41 | 42 | - (void)addAimView:(UIView *)ballView referenceView:(UIView *)referenceView { 43 | 44 | _referenceView = referenceView; 45 | 46 | [self.dynamic addItem:ballView]; 47 | [self.collision addItem:ballView]; 48 | [self.gravity addItem:ballView]; 49 | 50 | [self run]; 51 | 52 | 53 | } 54 | 55 | - (void)run { 56 | 57 | if (!self.manager.isDeviceMotionAvailable) { 58 | NSLog(@"换手机吧"); 59 | return; 60 | } 61 | 62 | self.manager.deviceMotionUpdateInterval = 0.01; 63 | 64 | __weak typeof(self) weakSelf = self; 65 | 66 | [self.manager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMDeviceMotion * _Nullable motion, NSError * _Nullable error) { 67 | 68 | if (error != nil) { 69 | NSLog(@"出错了 %@",error); 70 | return; 71 | } 72 | weakSelf.gravity.gravityDirection = CGVectorMake(motion.gravity.x * 3, -motion.gravity.y * 3); 73 | // self.bkView.transform = CGAffineTransformMakeRotation(atan2(motion.gravity.x, motion.gravity.y) - M_PI); 74 | }]; 75 | 76 | } 77 | # pragma mark - 停止运动 78 | - (void)stopMotionUpdates { 79 | 80 | if (self.manager.isDeviceMotionActive) { 81 | [self.manager stopDeviceMotionUpdates]; 82 | [self.animator removeAllBehaviors]; 83 | onceToken = 0; 84 | } 85 | } 86 | 87 | # pragma mark - 运动管理者 88 | - (CMMotionManager *)manager { 89 | 90 | 91 | if (_manager == nil) { 92 | _manager = [[CMMotionManager alloc] init]; 93 | } 94 | return _manager; 95 | } 96 | 97 | 98 | # pragma mark - 动态媒介 99 | - (UIDynamicAnimator *)animator { 100 | 101 | if (_animator == nil) { 102 | // 设置参考边界 103 | _animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.referenceView]; 104 | 105 | } 106 | 107 | return _animator; 108 | 109 | } 110 | # pragma mark - 重力 111 | - (UIGravityBehavior *)gravity { 112 | 113 | if (_gravity == nil) { 114 | 115 | _gravity = [[UIGravityBehavior alloc] init]; 116 | // _gravity.magnitude = 1.0; 117 | [self.animator addBehavior:_gravity]; 118 | } 119 | 120 | return _gravity; 121 | 122 | } 123 | # pragma mark - 碰撞 124 | - (UICollisionBehavior *)collision { 125 | 126 | if (_collision == nil) { 127 | 128 | _collision = [[UICollisionBehavior alloc] init]; 129 | _collision.translatesReferenceBoundsIntoBoundary = YES; 130 | _collision.collisionMode = UICollisionBehaviorModeEverything; 131 | [self.animator addBehavior:_collision]; 132 | } 133 | 134 | return _collision; 135 | 136 | } 137 | # pragma mark - 动力学属性 138 | - (UIDynamicItemBehavior *)dynamic { 139 | 140 | if (_dynamic == nil) { 141 | 142 | _dynamic = [[UIDynamicItemBehavior alloc] init]; 143 | _dynamic.friction = 0.2; 144 | _dynamic.elasticity = 0.8; 145 | _dynamic.density = 0.2; 146 | _dynamic.allowsRotation = YES; 147 | _dynamic.resistance = 0; 148 | [self.animator addBehavior:_dynamic]; 149 | } 150 | 151 | return _dynamic; 152 | 153 | } 154 | 155 | @end 156 | -------------------------------------------------------------------------------- /WLBallView/WLBallView/WLMotionView/WLBallView.h: -------------------------------------------------------------------------------- 1 | // 2 | // WLBallView.h 3 | // WLBallView 4 | // 5 | // Created by administrator on 2017/6/15. 6 | // Copyright © 2017年 WL. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WLBallView : UIImageView 12 | 13 | - (instancetype)initWithFrame:(CGRect)frame AndImageName:(NSString *)imageName; 14 | 15 | - (void)starMotion; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /WLBallView/WLBallView/WLMotionView/WLBallView.m: -------------------------------------------------------------------------------- 1 | // 2 | // WLBallView.m 3 | // WLBallView 4 | // 5 | // Created by administrator on 2017/6/15. 6 | // Copyright © 2017年 WL. All rights reserved. 7 | // 8 | 9 | #import "WLBallView.h" 10 | #import "WLBallTool.h" 11 | 12 | @interface WLBallView () 13 | 14 | @property (nonatomic, assign) UIDynamicItemCollisionBoundsType collisionBoundsType; 15 | 16 | @property (nonatomic, strong) WLBallTool * ball; 17 | 18 | @end 19 | 20 | @implementation WLBallView 21 | 22 | @synthesize collisionBoundsType; 23 | 24 | - (instancetype)initWithFrame:(CGRect)frame AndImageName:(NSString *)imageName { 25 | 26 | if (self = [super initWithFrame:frame]) { 27 | 28 | self.image = [UIImage imageNamed:imageName]; 29 | self.layer.cornerRadius = frame.size.width * 0.5; 30 | self.layer.masksToBounds = YES; 31 | self.collisionBoundsType = UIDynamicItemCollisionBoundsTypeEllipse; 32 | } 33 | 34 | return self; 35 | 36 | } 37 | 38 | 39 | - (void)starMotion { 40 | 41 | WLBallTool * ball = [WLBallTool shareBallTool]; 42 | 43 | [ball addAimView:self referenceView:self.superview]; 44 | } 45 | 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /WLBallView/WLBallView/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // WLBallView 4 | // 5 | // Created by administrator on 2017/6/16. 6 | // Copyright © 2017年 WL. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WLBallView/WLBallView/大师球.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coderLiuW/WLBallView/700686e4175bd976aaf9fe7a7d91f310c79f9f5a/WLBallView/WLBallView/大师球.png -------------------------------------------------------------------------------- /WLBallView/WLBallView/精灵球.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coderLiuW/WLBallView/700686e4175bd976aaf9fe7a7d91f310c79f9f5a/WLBallView/WLBallView/精灵球.png -------------------------------------------------------------------------------- /WLBallView/WLBallView/超级球.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coderLiuW/WLBallView/700686e4175bd976aaf9fe7a7d91f310c79f9f5a/WLBallView/WLBallView/超级球.png -------------------------------------------------------------------------------- /WLBallView/WLBallView/高级球.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coderLiuW/WLBallView/700686e4175bd976aaf9fe7a7d91f310c79f9f5a/WLBallView/WLBallView/高级球.png --------------------------------------------------------------------------------