├── .gitignore ├── LICENSE ├── README.md ├── SNKeyboardManagerDemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── SNKeyboardManagerDemo ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── SNKeyboardManager │ ├── UITextField+SNKeyboardManager.h │ ├── UITextField+SNKeyboardManager.m │ ├── UITextView+SNKeyboardManager.h │ ├── UITextView+SNKeyboardManager.m │ ├── UIView+SNRootView.h │ └── UIView+SNRootView.m ├── SecondViewController.h ├── SecondViewController.m ├── TableViewController.h ├── TableViewController.m ├── ViewController.h ├── ViewController.m └── main.m ├── SNKeyboardManagerDemoTests ├── Info.plist └── SNKeyboardManagerDemoTests.m ├── screenshot1.gif └── screenshot2.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xcuserstate 14 | *.xccheckout 15 | *.moved-aside 16 | DerivedData 17 | *.hmap 18 | *.ipa 19 | *.orig 20 | *.xcscmblueprint 21 | npm-debug.log 22 | # CocoaPods 23 | # 24 | # We recommend against adding the Pods directory to your .gitignore. However 25 | # you should judge for yourself, the pros and cons are mentioned at: 26 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control? 27 | # 28 | Pods/ 29 | 30 | 31 | ### AppCode ### 32 | ## Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 33 | # 34 | ### Directory-based project format 35 | .idea/ 36 | ## if you remove the above rule, at least ignore user-specific stuff: 37 | # .idea/workspace.xml 38 | ## .idea/tasks.xml 39 | ## and these sensitive or high-churn files: 40 | ## .idea/dataSources.ids 41 | ## .idea/dataSources.xml 42 | ## .idea/sqlDataSources.xml 43 | ## .idea/dynamic.xml 44 | # 45 | ### File-based project format 46 | *.ipr 47 | *.iml 48 | *.iws 49 | # 50 | ### Additional for IntelliJ 51 | out/ 52 | # 53 | ## generated by mpeltonen/sbt-idea plugin 54 | .idea_modules/ 55 | # 56 | ## generated by JIRA plugin 57 | atlassian-ide-plugin.xml 58 | # 59 | ## generated by Crashlytics plugin (for Android Studio and Intellij) 60 | com_crashlytics_export_strings.xml 61 | # 62 | # 63 | ReactComponent/ 64 | # 65 | ## React Native JS file 66 | # 67 | # 68 | cleanUUID.log 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Zip Lee 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 | # SNKeyboardManager 2 | 3 | [![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/jiaopen/MRRouter/blob/master/LICENSE.md) 4 | 5 | ## About 6 | SNKeyboardManager is a extend of UITextField/UITextView, you can control the keyboard event with a boolean property of UITextFiled/UITextView automatically and conviniently. 7 | 8 | 9 | ## Usage 10 | #####Tap or pan any blank area to turn off the keyboard: 11 | 12 | ```objc 13 | _textField.sn_keyboardManagerEnabled = YES; 14 | _textView.sn_keyboardManagerEnabled = YES; 15 | ``` 16 | ![image](https://github.com/jiaopen/SNKeyBoardManager/blob/master/screenshot1.gif) 17 | 18 | #####Adjust the position of view when keyboard is showing or dismissing: 19 | 20 | ```objc 21 | _textField.sn_autoAdjustFrameEnabled = YES; 22 | ``` 23 | ![image](https://github.com/jiaopen/SNKeyBoardManager/blob/master/screenshot2.gif) 24 | 25 | ## Requirements 26 | iOS 7.0+. 27 | 28 | ## License 29 | SNKeyboardManager is licensed under the [MIT License](http://opensource.org/licenses/mit-license.php). 30 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 8E63E3681C707E20006CCB2F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E63E3671C707E20006CCB2F /* main.m */; }; 11 | 8E63E36B1C707E20006CCB2F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E63E36A1C707E20006CCB2F /* AppDelegate.m */; }; 12 | 8E63E36E1C707E20006CCB2F /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E63E36D1C707E20006CCB2F /* ViewController.m */; }; 13 | 8E63E3711C707E20006CCB2F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8E63E36F1C707E20006CCB2F /* Main.storyboard */; }; 14 | 8E63E3731C707E20006CCB2F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8E63E3721C707E20006CCB2F /* Assets.xcassets */; }; 15 | 8E63E3761C707E20006CCB2F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8E63E3741C707E20006CCB2F /* LaunchScreen.storyboard */; }; 16 | 8E63E3811C707E20006CCB2F /* SNKeyboardManagerDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E63E3801C707E20006CCB2F /* SNKeyboardManagerDemoTests.m */; }; 17 | 8E63E39B1C708253006CCB2F /* UITextField+SNKeyboardManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E63E3961C708253006CCB2F /* UITextField+SNKeyboardManager.m */; }; 18 | 8E63E39C1C708253006CCB2F /* UITextView+SNKeyboardManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E63E3981C708253006CCB2F /* UITextView+SNKeyboardManager.m */; }; 19 | 8E63E39D1C708253006CCB2F /* UIView+SNRootView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E63E39A1C708253006CCB2F /* UIView+SNRootView.m */; }; 20 | 8EF5B9C71C71AEF700533935 /* TableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EF5B9C61C71AEF700533935 /* TableViewController.m */; }; 21 | 8EF5B9CA1C71B1F700533935 /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EF5B9C91C71B1F700533935 /* SecondViewController.m */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXContainerItemProxy section */ 25 | 8E63E37D1C707E20006CCB2F /* PBXContainerItemProxy */ = { 26 | isa = PBXContainerItemProxy; 27 | containerPortal = 8E63E35B1C707E20006CCB2F /* Project object */; 28 | proxyType = 1; 29 | remoteGlobalIDString = 8E63E3621C707E20006CCB2F; 30 | remoteInfo = SNKeyboardManagerDemo; 31 | }; 32 | /* End PBXContainerItemProxy section */ 33 | 34 | /* Begin PBXFileReference section */ 35 | 8E63E3631C707E20006CCB2F /* SNKeyboardManagerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SNKeyboardManagerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | 8E63E3671C707E20006CCB2F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 37 | 8E63E3691C707E20006CCB2F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 38 | 8E63E36A1C707E20006CCB2F /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 39 | 8E63E36C1C707E20006CCB2F /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 40 | 8E63E36D1C707E20006CCB2F /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 41 | 8E63E3701C707E20006CCB2F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 42 | 8E63E3721C707E20006CCB2F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 43 | 8E63E3751C707E20006CCB2F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 44 | 8E63E3771C707E20006CCB2F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | 8E63E37C1C707E20006CCB2F /* SNKeyboardManagerDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SNKeyboardManagerDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 46 | 8E63E3801C707E20006CCB2F /* SNKeyboardManagerDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SNKeyboardManagerDemoTests.m; sourceTree = ""; }; 47 | 8E63E3821C707E20006CCB2F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 48 | 8E63E3951C708253006CCB2F /* UITextField+SNKeyboardManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITextField+SNKeyboardManager.h"; sourceTree = ""; }; 49 | 8E63E3961C708253006CCB2F /* UITextField+SNKeyboardManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITextField+SNKeyboardManager.m"; sourceTree = ""; }; 50 | 8E63E3971C708253006CCB2F /* UITextView+SNKeyboardManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITextView+SNKeyboardManager.h"; sourceTree = ""; }; 51 | 8E63E3981C708253006CCB2F /* UITextView+SNKeyboardManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITextView+SNKeyboardManager.m"; sourceTree = ""; }; 52 | 8E63E3991C708253006CCB2F /* UIView+SNRootView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+SNRootView.h"; sourceTree = ""; }; 53 | 8E63E39A1C708253006CCB2F /* UIView+SNRootView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+SNRootView.m"; sourceTree = ""; }; 54 | 8EF5B9C51C71AEF700533935 /* TableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewController.h; sourceTree = ""; }; 55 | 8EF5B9C61C71AEF700533935 /* TableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewController.m; sourceTree = ""; }; 56 | 8EF5B9C81C71B1F700533935 /* SecondViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = ""; }; 57 | 8EF5B9C91C71B1F700533935 /* SecondViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = ""; }; 58 | /* End PBXFileReference section */ 59 | 60 | /* Begin PBXFrameworksBuildPhase section */ 61 | 8E63E3601C707E20006CCB2F /* Frameworks */ = { 62 | isa = PBXFrameworksBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | ); 66 | runOnlyForDeploymentPostprocessing = 0; 67 | }; 68 | 8E63E3791C707E20006CCB2F /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | /* End PBXFrameworksBuildPhase section */ 76 | 77 | /* Begin PBXGroup section */ 78 | 8E63E35A1C707E20006CCB2F = { 79 | isa = PBXGroup; 80 | children = ( 81 | 8E63E3651C707E20006CCB2F /* SNKeyboardManagerDemo */, 82 | 8E63E37F1C707E20006CCB2F /* SNKeyboardManagerDemoTests */, 83 | 8E63E3641C707E20006CCB2F /* Products */, 84 | ); 85 | sourceTree = ""; 86 | }; 87 | 8E63E3641C707E20006CCB2F /* Products */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 8E63E3631C707E20006CCB2F /* SNKeyboardManagerDemo.app */, 91 | 8E63E37C1C707E20006CCB2F /* SNKeyboardManagerDemoTests.xctest */, 92 | ); 93 | name = Products; 94 | sourceTree = ""; 95 | }; 96 | 8E63E3651C707E20006CCB2F /* SNKeyboardManagerDemo */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | 8E63E3941C708253006CCB2F /* SNKeyboardManager */, 100 | 8E63E3691C707E20006CCB2F /* AppDelegate.h */, 101 | 8E63E36A1C707E20006CCB2F /* AppDelegate.m */, 102 | 8E63E36C1C707E20006CCB2F /* ViewController.h */, 103 | 8E63E36D1C707E20006CCB2F /* ViewController.m */, 104 | 8EF5B9C51C71AEF700533935 /* TableViewController.h */, 105 | 8EF5B9C61C71AEF700533935 /* TableViewController.m */, 106 | 8EF5B9C81C71B1F700533935 /* SecondViewController.h */, 107 | 8EF5B9C91C71B1F700533935 /* SecondViewController.m */, 108 | 8E63E36F1C707E20006CCB2F /* Main.storyboard */, 109 | 8E63E3721C707E20006CCB2F /* Assets.xcassets */, 110 | 8E63E3741C707E20006CCB2F /* LaunchScreen.storyboard */, 111 | 8E63E3771C707E20006CCB2F /* Info.plist */, 112 | 8E63E3661C707E20006CCB2F /* Supporting Files */, 113 | ); 114 | path = SNKeyboardManagerDemo; 115 | sourceTree = ""; 116 | }; 117 | 8E63E3661C707E20006CCB2F /* Supporting Files */ = { 118 | isa = PBXGroup; 119 | children = ( 120 | 8E63E3671C707E20006CCB2F /* main.m */, 121 | ); 122 | name = "Supporting Files"; 123 | sourceTree = ""; 124 | }; 125 | 8E63E37F1C707E20006CCB2F /* SNKeyboardManagerDemoTests */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | 8E63E3801C707E20006CCB2F /* SNKeyboardManagerDemoTests.m */, 129 | 8E63E3821C707E20006CCB2F /* Info.plist */, 130 | ); 131 | path = SNKeyboardManagerDemoTests; 132 | sourceTree = ""; 133 | }; 134 | 8E63E3941C708253006CCB2F /* SNKeyboardManager */ = { 135 | isa = PBXGroup; 136 | children = ( 137 | 8E63E3951C708253006CCB2F /* UITextField+SNKeyboardManager.h */, 138 | 8E63E3961C708253006CCB2F /* UITextField+SNKeyboardManager.m */, 139 | 8E63E3971C708253006CCB2F /* UITextView+SNKeyboardManager.h */, 140 | 8E63E3981C708253006CCB2F /* UITextView+SNKeyboardManager.m */, 141 | 8E63E3991C708253006CCB2F /* UIView+SNRootView.h */, 142 | 8E63E39A1C708253006CCB2F /* UIView+SNRootView.m */, 143 | ); 144 | path = SNKeyboardManager; 145 | sourceTree = ""; 146 | }; 147 | /* End PBXGroup section */ 148 | 149 | /* Begin PBXNativeTarget section */ 150 | 8E63E3621C707E20006CCB2F /* SNKeyboardManagerDemo */ = { 151 | isa = PBXNativeTarget; 152 | buildConfigurationList = 8E63E3851C707E20006CCB2F /* Build configuration list for PBXNativeTarget "SNKeyboardManagerDemo" */; 153 | buildPhases = ( 154 | 8E63E35F1C707E20006CCB2F /* Sources */, 155 | 8E63E3601C707E20006CCB2F /* Frameworks */, 156 | 8E63E3611C707E20006CCB2F /* Resources */, 157 | ); 158 | buildRules = ( 159 | ); 160 | dependencies = ( 161 | ); 162 | name = SNKeyboardManagerDemo; 163 | productName = SNKeyboardManagerDemo; 164 | productReference = 8E63E3631C707E20006CCB2F /* SNKeyboardManagerDemo.app */; 165 | productType = "com.apple.product-type.application"; 166 | }; 167 | 8E63E37B1C707E20006CCB2F /* SNKeyboardManagerDemoTests */ = { 168 | isa = PBXNativeTarget; 169 | buildConfigurationList = 8E63E3881C707E20006CCB2F /* Build configuration list for PBXNativeTarget "SNKeyboardManagerDemoTests" */; 170 | buildPhases = ( 171 | 8E63E3781C707E20006CCB2F /* Sources */, 172 | 8E63E3791C707E20006CCB2F /* Frameworks */, 173 | 8E63E37A1C707E20006CCB2F /* Resources */, 174 | ); 175 | buildRules = ( 176 | ); 177 | dependencies = ( 178 | 8E63E37E1C707E20006CCB2F /* PBXTargetDependency */, 179 | ); 180 | name = SNKeyboardManagerDemoTests; 181 | productName = SNKeyboardManagerDemoTests; 182 | productReference = 8E63E37C1C707E20006CCB2F /* SNKeyboardManagerDemoTests.xctest */; 183 | productType = "com.apple.product-type.bundle.unit-test"; 184 | }; 185 | /* End PBXNativeTarget section */ 186 | 187 | /* Begin PBXProject section */ 188 | 8E63E35B1C707E20006CCB2F /* Project object */ = { 189 | isa = PBXProject; 190 | attributes = { 191 | LastUpgradeCheck = 0720; 192 | ORGANIZATIONNAME = juangua; 193 | TargetAttributes = { 194 | 8E63E3621C707E20006CCB2F = { 195 | CreatedOnToolsVersion = 7.2; 196 | }; 197 | 8E63E37B1C707E20006CCB2F = { 198 | CreatedOnToolsVersion = 7.2; 199 | TestTargetID = 8E63E3621C707E20006CCB2F; 200 | }; 201 | }; 202 | }; 203 | buildConfigurationList = 8E63E35E1C707E20006CCB2F /* Build configuration list for PBXProject "SNKeyboardManagerDemo" */; 204 | compatibilityVersion = "Xcode 3.2"; 205 | developmentRegion = English; 206 | hasScannedForEncodings = 0; 207 | knownRegions = ( 208 | en, 209 | Base, 210 | ); 211 | mainGroup = 8E63E35A1C707E20006CCB2F; 212 | productRefGroup = 8E63E3641C707E20006CCB2F /* Products */; 213 | projectDirPath = ""; 214 | projectRoot = ""; 215 | targets = ( 216 | 8E63E3621C707E20006CCB2F /* SNKeyboardManagerDemo */, 217 | 8E63E37B1C707E20006CCB2F /* SNKeyboardManagerDemoTests */, 218 | ); 219 | }; 220 | /* End PBXProject section */ 221 | 222 | /* Begin PBXResourcesBuildPhase section */ 223 | 8E63E3611C707E20006CCB2F /* Resources */ = { 224 | isa = PBXResourcesBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | 8E63E3761C707E20006CCB2F /* LaunchScreen.storyboard in Resources */, 228 | 8E63E3731C707E20006CCB2F /* Assets.xcassets in Resources */, 229 | 8E63E3711C707E20006CCB2F /* Main.storyboard in Resources */, 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | }; 233 | 8E63E37A1C707E20006CCB2F /* Resources */ = { 234 | isa = PBXResourcesBuildPhase; 235 | buildActionMask = 2147483647; 236 | files = ( 237 | ); 238 | runOnlyForDeploymentPostprocessing = 0; 239 | }; 240 | /* End PBXResourcesBuildPhase section */ 241 | 242 | /* Begin PBXSourcesBuildPhase section */ 243 | 8E63E35F1C707E20006CCB2F /* Sources */ = { 244 | isa = PBXSourcesBuildPhase; 245 | buildActionMask = 2147483647; 246 | files = ( 247 | 8E63E36E1C707E20006CCB2F /* ViewController.m in Sources */, 248 | 8EF5B9CA1C71B1F700533935 /* SecondViewController.m in Sources */, 249 | 8EF5B9C71C71AEF700533935 /* TableViewController.m in Sources */, 250 | 8E63E39D1C708253006CCB2F /* UIView+SNRootView.m in Sources */, 251 | 8E63E39C1C708253006CCB2F /* UITextView+SNKeyboardManager.m in Sources */, 252 | 8E63E39B1C708253006CCB2F /* UITextField+SNKeyboardManager.m in Sources */, 253 | 8E63E36B1C707E20006CCB2F /* AppDelegate.m in Sources */, 254 | 8E63E3681C707E20006CCB2F /* main.m in Sources */, 255 | ); 256 | runOnlyForDeploymentPostprocessing = 0; 257 | }; 258 | 8E63E3781C707E20006CCB2F /* Sources */ = { 259 | isa = PBXSourcesBuildPhase; 260 | buildActionMask = 2147483647; 261 | files = ( 262 | 8E63E3811C707E20006CCB2F /* SNKeyboardManagerDemoTests.m in Sources */, 263 | ); 264 | runOnlyForDeploymentPostprocessing = 0; 265 | }; 266 | /* End PBXSourcesBuildPhase section */ 267 | 268 | /* Begin PBXTargetDependency section */ 269 | 8E63E37E1C707E20006CCB2F /* PBXTargetDependency */ = { 270 | isa = PBXTargetDependency; 271 | target = 8E63E3621C707E20006CCB2F /* SNKeyboardManagerDemo */; 272 | targetProxy = 8E63E37D1C707E20006CCB2F /* PBXContainerItemProxy */; 273 | }; 274 | /* End PBXTargetDependency section */ 275 | 276 | /* Begin PBXVariantGroup section */ 277 | 8E63E36F1C707E20006CCB2F /* Main.storyboard */ = { 278 | isa = PBXVariantGroup; 279 | children = ( 280 | 8E63E3701C707E20006CCB2F /* Base */, 281 | ); 282 | name = Main.storyboard; 283 | sourceTree = ""; 284 | }; 285 | 8E63E3741C707E20006CCB2F /* LaunchScreen.storyboard */ = { 286 | isa = PBXVariantGroup; 287 | children = ( 288 | 8E63E3751C707E20006CCB2F /* Base */, 289 | ); 290 | name = LaunchScreen.storyboard; 291 | sourceTree = ""; 292 | }; 293 | /* End PBXVariantGroup section */ 294 | 295 | /* Begin XCBuildConfiguration section */ 296 | 8E63E3831C707E20006CCB2F /* Debug */ = { 297 | isa = XCBuildConfiguration; 298 | buildSettings = { 299 | ALWAYS_SEARCH_USER_PATHS = NO; 300 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 301 | CLANG_CXX_LIBRARY = "libc++"; 302 | CLANG_ENABLE_MODULES = YES; 303 | CLANG_ENABLE_OBJC_ARC = YES; 304 | CLANG_WARN_BOOL_CONVERSION = YES; 305 | CLANG_WARN_CONSTANT_CONVERSION = YES; 306 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 307 | CLANG_WARN_EMPTY_BODY = YES; 308 | CLANG_WARN_ENUM_CONVERSION = YES; 309 | CLANG_WARN_INT_CONVERSION = YES; 310 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 311 | CLANG_WARN_UNREACHABLE_CODE = YES; 312 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 313 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 314 | COPY_PHASE_STRIP = NO; 315 | DEBUG_INFORMATION_FORMAT = dwarf; 316 | ENABLE_STRICT_OBJC_MSGSEND = YES; 317 | ENABLE_TESTABILITY = YES; 318 | GCC_C_LANGUAGE_STANDARD = gnu99; 319 | GCC_DYNAMIC_NO_PIC = NO; 320 | GCC_NO_COMMON_BLOCKS = YES; 321 | GCC_OPTIMIZATION_LEVEL = 0; 322 | GCC_PREPROCESSOR_DEFINITIONS = ( 323 | "DEBUG=1", 324 | "$(inherited)", 325 | ); 326 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 327 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 328 | GCC_WARN_UNDECLARED_SELECTOR = YES; 329 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 330 | GCC_WARN_UNUSED_FUNCTION = YES; 331 | GCC_WARN_UNUSED_VARIABLE = YES; 332 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 333 | MTL_ENABLE_DEBUG_INFO = YES; 334 | ONLY_ACTIVE_ARCH = YES; 335 | SDKROOT = iphoneos; 336 | }; 337 | name = Debug; 338 | }; 339 | 8E63E3841C707E20006CCB2F /* Release */ = { 340 | isa = XCBuildConfiguration; 341 | buildSettings = { 342 | ALWAYS_SEARCH_USER_PATHS = NO; 343 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 344 | CLANG_CXX_LIBRARY = "libc++"; 345 | CLANG_ENABLE_MODULES = YES; 346 | CLANG_ENABLE_OBJC_ARC = YES; 347 | CLANG_WARN_BOOL_CONVERSION = YES; 348 | CLANG_WARN_CONSTANT_CONVERSION = YES; 349 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 350 | CLANG_WARN_EMPTY_BODY = YES; 351 | CLANG_WARN_ENUM_CONVERSION = YES; 352 | CLANG_WARN_INT_CONVERSION = YES; 353 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 354 | CLANG_WARN_UNREACHABLE_CODE = YES; 355 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 356 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 357 | COPY_PHASE_STRIP = NO; 358 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 359 | ENABLE_NS_ASSERTIONS = NO; 360 | ENABLE_STRICT_OBJC_MSGSEND = YES; 361 | GCC_C_LANGUAGE_STANDARD = gnu99; 362 | GCC_NO_COMMON_BLOCKS = YES; 363 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 364 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 365 | GCC_WARN_UNDECLARED_SELECTOR = YES; 366 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 367 | GCC_WARN_UNUSED_FUNCTION = YES; 368 | GCC_WARN_UNUSED_VARIABLE = YES; 369 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 370 | MTL_ENABLE_DEBUG_INFO = NO; 371 | SDKROOT = iphoneos; 372 | VALIDATE_PRODUCT = YES; 373 | }; 374 | name = Release; 375 | }; 376 | 8E63E3861C707E20006CCB2F /* Debug */ = { 377 | isa = XCBuildConfiguration; 378 | buildSettings = { 379 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 380 | INFOPLIST_FILE = SNKeyboardManagerDemo/Info.plist; 381 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 382 | PRODUCT_BUNDLE_IDENTIFIER = juangua.SNKeyboardManagerDemo; 383 | PRODUCT_NAME = "$(TARGET_NAME)"; 384 | }; 385 | name = Debug; 386 | }; 387 | 8E63E3871C707E20006CCB2F /* Release */ = { 388 | isa = XCBuildConfiguration; 389 | buildSettings = { 390 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 391 | INFOPLIST_FILE = SNKeyboardManagerDemo/Info.plist; 392 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 393 | PRODUCT_BUNDLE_IDENTIFIER = juangua.SNKeyboardManagerDemo; 394 | PRODUCT_NAME = "$(TARGET_NAME)"; 395 | }; 396 | name = Release; 397 | }; 398 | 8E63E3891C707E20006CCB2F /* Debug */ = { 399 | isa = XCBuildConfiguration; 400 | buildSettings = { 401 | BUNDLE_LOADER = "$(TEST_HOST)"; 402 | INFOPLIST_FILE = SNKeyboardManagerDemoTests/Info.plist; 403 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 404 | PRODUCT_BUNDLE_IDENTIFIER = juangua.SNKeyboardManagerDemoTests; 405 | PRODUCT_NAME = "$(TARGET_NAME)"; 406 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SNKeyboardManagerDemo.app/SNKeyboardManagerDemo"; 407 | }; 408 | name = Debug; 409 | }; 410 | 8E63E38A1C707E20006CCB2F /* Release */ = { 411 | isa = XCBuildConfiguration; 412 | buildSettings = { 413 | BUNDLE_LOADER = "$(TEST_HOST)"; 414 | INFOPLIST_FILE = SNKeyboardManagerDemoTests/Info.plist; 415 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 416 | PRODUCT_BUNDLE_IDENTIFIER = juangua.SNKeyboardManagerDemoTests; 417 | PRODUCT_NAME = "$(TARGET_NAME)"; 418 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SNKeyboardManagerDemo.app/SNKeyboardManagerDemo"; 419 | }; 420 | name = Release; 421 | }; 422 | /* End XCBuildConfiguration section */ 423 | 424 | /* Begin XCConfigurationList section */ 425 | 8E63E35E1C707E20006CCB2F /* Build configuration list for PBXProject "SNKeyboardManagerDemo" */ = { 426 | isa = XCConfigurationList; 427 | buildConfigurations = ( 428 | 8E63E3831C707E20006CCB2F /* Debug */, 429 | 8E63E3841C707E20006CCB2F /* Release */, 430 | ); 431 | defaultConfigurationIsVisible = 0; 432 | defaultConfigurationName = Release; 433 | }; 434 | 8E63E3851C707E20006CCB2F /* Build configuration list for PBXNativeTarget "SNKeyboardManagerDemo" */ = { 435 | isa = XCConfigurationList; 436 | buildConfigurations = ( 437 | 8E63E3861C707E20006CCB2F /* Debug */, 438 | 8E63E3871C707E20006CCB2F /* Release */, 439 | ); 440 | defaultConfigurationIsVisible = 0; 441 | defaultConfigurationName = Release; 442 | }; 443 | 8E63E3881C707E20006CCB2F /* Build configuration list for PBXNativeTarget "SNKeyboardManagerDemoTests" */ = { 444 | isa = XCConfigurationList; 445 | buildConfigurations = ( 446 | 8E63E3891C707E20006CCB2F /* Debug */, 447 | 8E63E38A1C707E20006CCB2F /* Release */, 448 | ); 449 | defaultConfigurationIsVisible = 0; 450 | defaultConfigurationName = Release; 451 | }; 452 | /* End XCConfigurationList section */ 453 | }; 454 | rootObject = 8E63E35B1C707E20006CCB2F /* Project object */; 455 | } 456 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // SNKeyboardManagerDemo 4 | // 5 | // Created by 苏合 on 16/2/14. 6 | // Copyright © 2016年 juangua. 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 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // SNKeyboardManagerDemo 4 | // 5 | // Created by 苏合 on 16/2/14. 6 | // Copyright © 2016年 juangua. 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 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/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 | } -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/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 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/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 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/SNKeyboardManager/UITextField+SNKeyboardManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+SNKeyboardManager.h 3 | // SNKeyboardManager 4 | // 5 | // Created by 苏合 on 16/2/14. 6 | // Copyright © 2016年 juangua. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UITextField (SNKeyboardManager) 12 | 13 | /** Default is NO. */ 14 | @property(nonatomic, assign, getter=isKeyboardManagerEnabled) BOOL sn_keyboardManagerEnabled; 15 | 16 | /** Whether enable adjust the frame automatically, default is NO. */ 17 | @property(nonatomic, assign, getter=isAutoAdjustFrameEnabled) BOOL sn_autoAdjustFrameEnabled; 18 | 19 | /** The distance between keyboard with text field after adjust frame, default is 10.f. */ 20 | @property(nonatomic, assign) CGFloat sn_keyboardDistance; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/SNKeyboardManager/UITextField+SNKeyboardManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+SNKeyboardManager.m 3 | // SNKeyboardManager 4 | // 5 | // Created by 苏合 on 16/2/14. 6 | // Copyright © 2016年 juangua. All rights reserved. 7 | // 8 | 9 | #import "UITextField+SNKeyboardManager.h" 10 | #import "UIView+SNRootView.h" 11 | #import 12 | 13 | #define kDEFAULT_KEYBORAD_DISTANCE 10.f 14 | 15 | 16 | @interface UITextField () 17 | 18 | @property (nonatomic, strong) UITapGestureRecognizer *sn_tapGestureRecognizer; 19 | @property (nonatomic, strong) UIPanGestureRecognizer *sn_panGestureRecognizer; 20 | @property (nonatomic, assign, getter=isRectAdjusted) BOOL rectAdjusted; 21 | @property (nonatomic, assign) BOOL haveOtherResponder; 22 | 23 | 24 | @end 25 | 26 | @implementation UITextField (SNKeyboardManager) 27 | 28 | + (void)load { 29 | static dispatch_once_t onceToken; 30 | dispatch_once(&onceToken, ^{ 31 | 32 | SEL selectors[] = { 33 | NSSelectorFromString(@"dealloc"), 34 | @selector(becomeFirstResponder), 35 | @selector(resignFirstResponder), 36 | }; 37 | 38 | for (NSUInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) { 39 | SEL originalSelector = selectors[index]; 40 | SEL swizzledSelector = NSSelectorFromString([@"sn_" stringByAppendingString:NSStringFromSelector(originalSelector)]); 41 | 42 | Method originalMethod = class_getInstanceMethod(self, originalSelector); 43 | Method swizzledMethod = class_getInstanceMethod(self, swizzledSelector); 44 | 45 | BOOL addedSuccess = class_addMethod(self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); 46 | if (addedSuccess) 47 | { 48 | class_replaceMethod(self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); 49 | } 50 | else 51 | { 52 | method_exchangeImplementations(originalMethod, swizzledMethod); 53 | } 54 | } 55 | }); 56 | } 57 | 58 | -(void)sn_dealloc 59 | { 60 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 61 | [self removeGestureRecognizer]; 62 | [self sn_dealloc]; 63 | } 64 | 65 | -(void)sn_becomeFirstResponder 66 | { 67 | [self sn_becomeFirstResponder]; 68 | } 69 | 70 | -(void)sn_resignFirstResponder 71 | { 72 | [self sn_resignFirstResponder]; 73 | if (!CGRectEqualToRect(self.sn_rootView.frame, self.window.frame)) { 74 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 75 | if (!self.haveOtherResponder) { 76 | [UIView animateWithDuration:0.2 77 | delay:0.0f 78 | options:UIViewAnimationOptionCurveLinear 79 | animations:^{ 80 | self.sn_rootView.frame = self.window.frame; 81 | } 82 | completion:^(BOOL finished) { 83 | self.rectAdjusted = NO; 84 | }]; 85 | } 86 | }); 87 | } 88 | } 89 | 90 | 91 | - (void)handleWillShowKeyboard:(NSNotification *)notification 92 | { 93 | if (!self.window) 94 | { 95 | return; 96 | } 97 | if(!self.isFirstResponder) 98 | { 99 | self.haveOtherResponder = YES; 100 | [self removeGestureRecognizer]; 101 | return; 102 | } 103 | self.haveOtherResponder = NO; 104 | if (!self.sn_tapGestureRecognizer) 105 | { 106 | self.sn_tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]; 107 | self.sn_tapGestureRecognizer.delegate = self; 108 | [self.sn_rootView addGestureRecognizer:self.sn_tapGestureRecognizer]; 109 | } 110 | if (!self.sn_panGestureRecognizer) 111 | { 112 | self.sn_panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)]; 113 | self.sn_panGestureRecognizer.delegate = self; 114 | [self.sn_rootView addGestureRecognizer:self.sn_panGestureRecognizer]; 115 | } 116 | 117 | if (self.isAutoAdjustFrameEnabled) 118 | { 119 | CGRect keyboardRect = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; 120 | keyboardRect = [self.sn_rootView convertRect:keyboardRect fromView:nil]; 121 | CGRect rectInWindow = [self convertRect:self.bounds toView:self.window]; 122 | rectInWindow = CGRectMake(0, rectInWindow.origin.y, self.window.frame.size.width, rectInWindow.size.height); 123 | 124 | CGRect rectOutsideKeyboard = CGRectMake(0.f, 64.f, keyboardRect.size.width, keyboardRect.origin.y - 64.f); 125 | double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; 126 | UIViewAnimationCurve curve = [[notification.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue]; 127 | 128 | if (!CGRectContainsRect(rectOutsideKeyboard, rectInWindow)) 129 | { 130 | CGFloat yOffset = self.sn_keyboardDistance + (rectInWindow.origin.y + rectInWindow.size.height) - keyboardRect.origin.y; 131 | [UIView animateWithDuration:duration 132 | delay:0.0f 133 | options:[UIView sn_animationOptionsForCurve:curve] 134 | animations:^{ 135 | self.rectAdjusted = YES; 136 | self.sn_rootView.frame = CGRectOffset(self.sn_rootView.frame, 0, -yOffset); 137 | } 138 | completion:^(BOOL finished) { 139 | }]; 140 | } 141 | } 142 | } 143 | 144 | - (void)handleWillHideKeyboard:(NSNotification *)notification 145 | { 146 | if (!self.sn_tapGestureRecognizer && !CGRectEqualToRect(self.sn_rootView.frame, self.window.frame)) { 147 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 148 | [UIView animateWithDuration:0.2 149 | delay:0.0f 150 | options:UIViewAnimationOptionCurveLinear 151 | animations:^{ 152 | self.sn_rootView.frame = self.window.frame; 153 | } 154 | completion:^(BOOL finished) { 155 | self.rectAdjusted = NO; 156 | }]; 157 | }); 158 | } 159 | [self removeGestureRecognizer]; 160 | } 161 | 162 | - (void)handleDidHideKeyboard:(NSNotification *)notification 163 | { 164 | self.haveOtherResponder = NO; 165 | } 166 | 167 | -(void)textFieldViewDidEndEditing:(NSNotification*)notification 168 | { 169 | } 170 | 171 | #pragma mark GestureRecognizerHandle 172 | 173 | - (void)tap:(UITapGestureRecognizer *)gestureRecognizer 174 | { 175 | [self resignFirstResponder]; 176 | [self.sn_rootView removeGestureRecognizer:gestureRecognizer]; 177 | self.sn_tapGestureRecognizer = nil; 178 | } 179 | 180 | - (void)pan:(UIPanGestureRecognizer *)gestureRecognizer 181 | { 182 | [self resignFirstResponder]; 183 | [self.sn_rootView removeGestureRecognizer:gestureRecognizer]; 184 | self.sn_panGestureRecognizer = nil; 185 | } 186 | 187 | - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 188 | { 189 | if ([self.gestureRecognizers containsObject:otherGestureRecognizer]) 190 | { 191 | return NO; 192 | } 193 | return YES; 194 | } 195 | 196 | #pragma mark - setter & getter 197 | 198 | -(void)setSn_keyboardManagerEnabled:(BOOL)sn_keyboardManagerEnabled 199 | { 200 | objc_setAssociatedObject(self, @selector(isKeyboardManagerEnabled), @(sn_keyboardManagerEnabled), OBJC_ASSOCIATION_ASSIGN); 201 | if (sn_keyboardManagerEnabled) 202 | { 203 | [[NSNotificationCenter defaultCenter] addObserver:self 204 | selector:@selector(handleWillShowKeyboard:) 205 | name:UIKeyboardWillShowNotification 206 | object:nil]; 207 | [[NSNotificationCenter defaultCenter] addObserver:self 208 | selector:@selector(handleWillHideKeyboard:) 209 | name:UIKeyboardWillHideNotification 210 | object:nil]; 211 | [[NSNotificationCenter defaultCenter] addObserver:self 212 | selector:@selector(handleDidHideKeyboard:) 213 | name:UIKeyboardDidHideNotification 214 | object:nil]; 215 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldViewDidEndEditing:) name:UITextFieldTextDidEndEditingNotification object:nil]; 216 | 217 | } 218 | else 219 | { 220 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 221 | } 222 | } 223 | 224 | -(BOOL)isKeyboardManagerEnabled 225 | { 226 | return [objc_getAssociatedObject(self, _cmd) boolValue]; 227 | } 228 | 229 | -(void)setSn_autoAdjustFrameEnabled:(BOOL)sn_autoAdjustFrameEnabled 230 | { 231 | objc_setAssociatedObject(self, @selector(isAutoAdjustFrameEnabled), @(sn_autoAdjustFrameEnabled), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 232 | } 233 | 234 | -(BOOL)isAutoAdjustFrameEnabled 235 | { 236 | return [objc_getAssociatedObject(self, _cmd) boolValue]; 237 | } 238 | 239 | - (void)setSn_keyboardDistance:(CGFloat)sn_keyboardDistance 240 | { 241 | objc_setAssociatedObject(self, @selector(sn_keyboardDistance), @(sn_keyboardDistance), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 242 | } 243 | 244 | - (CGFloat)sn_keyboardDistance 245 | { 246 | NSNumber *distance = objc_getAssociatedObject(self, _cmd); 247 | if (distance) 248 | { 249 | return [distance floatValue]; 250 | } 251 | else 252 | { 253 | return kDEFAULT_KEYBORAD_DISTANCE; 254 | } 255 | } 256 | 257 | - (void)setRectAdjusted:(BOOL)rectAdjusted 258 | { 259 | objc_setAssociatedObject(self, @selector(isRectAdjusted), @(rectAdjusted), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 260 | } 261 | 262 | - (BOOL)isRectAdjusted 263 | { 264 | return [objc_getAssociatedObject(self, _cmd) boolValue]; 265 | } 266 | 267 | - (void)setHaveOtherResponder:(BOOL)haveOtherResponder 268 | { 269 | objc_setAssociatedObject(self, @selector(haveOtherResponder), @(haveOtherResponder), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 270 | } 271 | 272 | - (BOOL)haveOtherResponder 273 | { 274 | return [objc_getAssociatedObject(self, _cmd) boolValue]; 275 | } 276 | 277 | 278 | - (void)setSn_panGestureRecognizer:(UIPanGestureRecognizer *)sn_panGestureRecognizer 279 | { 280 | objc_setAssociatedObject(self, @selector(sn_panGestureRecognizer), sn_panGestureRecognizer, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 281 | } 282 | 283 | - (UIPanGestureRecognizer *)sn_panGestureRecognizer 284 | { 285 | return objc_getAssociatedObject(self, _cmd); 286 | } 287 | 288 | - (void)setSn_tapGestureRecognizer:(UITapGestureRecognizer *)sn_tapGestureRecognizer 289 | { 290 | objc_setAssociatedObject(self, @selector(sn_tapGestureRecognizer), sn_tapGestureRecognizer, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 291 | } 292 | 293 | - (UITapGestureRecognizer *)sn_tapGestureRecognizer 294 | { 295 | return objc_getAssociatedObject(self, _cmd); 296 | } 297 | 298 | - (void)removeGestureRecognizer 299 | { 300 | if (self.sn_tapGestureRecognizer) 301 | { 302 | [self.sn_rootView removeGestureRecognizer:self.sn_tapGestureRecognizer]; 303 | self.sn_tapGestureRecognizer = nil; 304 | } 305 | if (self.sn_panGestureRecognizer) 306 | { 307 | [self.sn_rootView removeGestureRecognizer:self.sn_panGestureRecognizer]; 308 | self.sn_panGestureRecognizer = nil; 309 | } 310 | } 311 | 312 | @end 313 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/SNKeyboardManager/UITextView+SNKeyboardManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITextView+SNKeyboardManager.h 3 | // SNKeyboardManager 4 | // 5 | // Created by 苏合 on 16/2/14. 6 | // Copyright © 2016年 juangua. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UITextView (SNKeyboardManager) 12 | 13 | /** Default is NO. */ 14 | @property(nonatomic, assign, getter=isKeyboardManagerEnabled) BOOL sn_keyboardManagerEnabled; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/SNKeyboardManager/UITextView+SNKeyboardManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITextView+SNKeyboardManager.m 3 | // SNKeyboardManager 4 | // 5 | // Created by 苏合 on 16/2/14. 6 | // Copyright © 2016年 juangua. All rights reserved. 7 | // 8 | 9 | #import "UITextView+SNKeyboardManager.h" 10 | #import "UIView+SNRootView.h" 11 | #import 12 | 13 | @interface UITextView () 14 | 15 | @property (nonatomic, strong) UITapGestureRecognizer *sn_tapGestureRecognizer; 16 | @property (nonatomic, strong) UIPanGestureRecognizer *sn_panGestureRecognizer; 17 | 18 | @end 19 | 20 | @implementation UITextView (SNKeyboardManager) 21 | 22 | + (void)load { 23 | static dispatch_once_t onceToken; 24 | dispatch_once(&onceToken, ^{ 25 | 26 | SEL selectors[] = { 27 | NSSelectorFromString(@"dealloc"), 28 | @selector(becomeFirstResponder), 29 | @selector(resignFirstResponder), 30 | }; 31 | 32 | for (NSUInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) { 33 | SEL originalSelector = selectors[index]; 34 | SEL swizzledSelector = NSSelectorFromString([@"sn_" stringByAppendingString:NSStringFromSelector(originalSelector)]); 35 | 36 | Method originalMethod = class_getInstanceMethod(self, originalSelector); 37 | Method swizzledMethod = class_getInstanceMethod(self, swizzledSelector); 38 | 39 | BOOL addedSuccess = class_addMethod(self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); 40 | if (addedSuccess) 41 | { 42 | class_replaceMethod(self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); 43 | } 44 | else 45 | { 46 | method_exchangeImplementations(originalMethod, swizzledMethod); 47 | } 48 | } 49 | }); 50 | } 51 | 52 | -(void)sn_dealloc 53 | { 54 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 55 | [self removeGestureRecognizer]; 56 | [self sn_dealloc]; 57 | } 58 | 59 | -(void)sn_becomeFirstResponder 60 | { 61 | [self sn_becomeFirstResponder]; 62 | if (self.sn_keyboardManagerEnabled) 63 | { 64 | if (!self.sn_tapGestureRecognizer) 65 | { 66 | self.sn_tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]; 67 | self.sn_tapGestureRecognizer.delegate = self; 68 | [self.sn_rootView addGestureRecognizer:self.sn_tapGestureRecognizer]; 69 | } 70 | if (!self.sn_panGestureRecognizer) 71 | { 72 | self.sn_panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)]; 73 | self.sn_panGestureRecognizer.delegate = self; 74 | [self.sn_rootView addGestureRecognizer:self.sn_panGestureRecognizer]; 75 | } 76 | } 77 | } 78 | 79 | -(void)sn_resignFirstResponder 80 | { 81 | [self sn_resignFirstResponder]; 82 | if (self.sn_keyboardManagerEnabled) 83 | { 84 | [self removeGestureRecognizer]; 85 | } 86 | } 87 | 88 | #pragma mark GestureRecognizerHandle 89 | 90 | - (void)tap:(UITapGestureRecognizer *)gestureRecognizer 91 | { 92 | [self resignFirstResponder]; 93 | [self.sn_rootView removeGestureRecognizer:gestureRecognizer]; 94 | self.sn_tapGestureRecognizer = nil; 95 | } 96 | 97 | - (void)pan:(UIPanGestureRecognizer *)gestureRecognizer 98 | { 99 | [self resignFirstResponder]; 100 | [self.sn_rootView removeGestureRecognizer:gestureRecognizer]; 101 | self.sn_panGestureRecognizer = nil; 102 | } 103 | 104 | - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 105 | { 106 | if ([self.gestureRecognizers containsObject:otherGestureRecognizer]) 107 | { 108 | return NO; 109 | } 110 | return YES; 111 | } 112 | 113 | #pragma mark - setter & getter 114 | 115 | -(void)setSn_keyboardManagerEnabled:(BOOL)sn_keyboardManagerEnabled 116 | { 117 | objc_setAssociatedObject(self, @selector(isKeyboardManagerEnabled), @(sn_keyboardManagerEnabled), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 118 | 119 | } 120 | 121 | -(BOOL)isKeyboardManagerEnabled 122 | { 123 | return [objc_getAssociatedObject(self, _cmd) boolValue]; 124 | } 125 | 126 | -(void)setSn_panGestureRecognizer:(UIPanGestureRecognizer *)sn_panGestureRecognizer 127 | { 128 | objc_setAssociatedObject(self, @selector(sn_panGestureRecognizer), sn_panGestureRecognizer, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 129 | } 130 | 131 | -(UIPanGestureRecognizer *)sn_panGestureRecognizer 132 | { 133 | return objc_getAssociatedObject(self, _cmd); 134 | } 135 | 136 | -(void)setSn_tapGestureRecognizer:(UITapGestureRecognizer *)sn_tapGestureRecognizer 137 | { 138 | objc_setAssociatedObject(self, @selector(sn_tapGestureRecognizer), sn_tapGestureRecognizer, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 139 | } 140 | 141 | -(UITapGestureRecognizer *)sn_tapGestureRecognizer 142 | { 143 | return objc_getAssociatedObject(self, _cmd); 144 | } 145 | 146 | - (void)removeGestureRecognizer 147 | { 148 | if (self.sn_tapGestureRecognizer) 149 | { 150 | [self.sn_rootView removeGestureRecognizer:self.sn_tapGestureRecognizer]; 151 | self.sn_tapGestureRecognizer = nil; 152 | } 153 | if (self.sn_panGestureRecognizer) 154 | { 155 | [self.sn_rootView removeGestureRecognizer:self.sn_panGestureRecognizer]; 156 | self.sn_panGestureRecognizer = nil; 157 | } 158 | } 159 | 160 | @end 161 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/SNKeyboardManager/UIView+SNRootView.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+SNExtensions.h 3 | // SNKeyboardManager 4 | // 5 | // Created by 苏合 on 16/1/21. 6 | // Copyright © 2016年 juangua. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (SNRootView) 12 | 13 | /** 当前view所在的rootView,window的下一级 */ 14 | @property (nonatomic, strong, readonly) UIView *sn_rootView; 15 | 16 | /** 当前view的容器view,如果当前view是rootview的subview,则直接返回当前view */ 17 | @property (nonatomic, strong, readonly) UIView *sn_containerView; 18 | 19 | + (UIViewAnimationOptions)sn_animationOptionsForCurve:(UIViewAnimationCurve)curve; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/SNKeyboardManager/UIView+SNRootView.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+SNExtensions.m 3 | // SNKeyboardManager 4 | // 5 | // Created by 苏合 on 16/1/21. 6 | // Copyright © 2016年 juangua. All rights reserved. 7 | // 8 | 9 | #import "UIView+SNRootView.h" 10 | #import 11 | 12 | @implementation UIView (SNRootView) 13 | 14 | - (UIView *)sn_rootView 15 | { 16 | UIView *superView = self.superview; 17 | if ([NSStringFromClass([superView class]) isEqualToString:@"UIViewControllerWrapperView"]) 18 | { 19 | return self; 20 | } 21 | else 22 | { 23 | return superView.sn_rootView; 24 | } 25 | } 26 | 27 | - (UIView *)sn_containerView 28 | { 29 | UIView *superView = self.superview; 30 | if (superView == self.sn_rootView) 31 | { 32 | return self; 33 | } 34 | else 35 | { 36 | return superView.sn_containerView; 37 | } 38 | } 39 | 40 | + (UIViewAnimationOptions)sn_animationOptionsForCurve:(UIViewAnimationCurve)curve 41 | { 42 | switch (curve) { 43 | case UIViewAnimationCurveEaseInOut: 44 | return UIViewAnimationOptionCurveEaseInOut; 45 | break; 46 | case UIViewAnimationCurveEaseIn: 47 | return UIViewAnimationOptionCurveEaseIn; 48 | break; 49 | case UIViewAnimationCurveEaseOut: 50 | return UIViewAnimationOptionCurveEaseOut; 51 | break; 52 | case UIViewAnimationCurveLinear: 53 | return UIViewAnimationOptionCurveLinear; 54 | break; 55 | } 56 | 57 | return kNilOptions; 58 | } 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/SecondViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.h 3 | // SNKeyboardManagerDemo 4 | // 5 | // Created by 苏合 on 16/2/15. 6 | // Copyright © 2016年 juangua. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SecondViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/SecondViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.m 3 | // SNKeyboardManagerDemo 4 | // 5 | // Created by 苏合 on 16/2/15. 6 | // Copyright © 2016年 juangua. All rights reserved. 7 | // 8 | 9 | #import "SecondViewController.h" 10 | #import "UITextField+SNKeyboardManager.h" 11 | 12 | @interface SecondViewController () 13 | 14 | @property (weak, nonatomic) IBOutlet UIScrollView *scrollview; 15 | @property (weak, nonatomic) IBOutlet UITextField *textField; 16 | 17 | @end 18 | 19 | @implementation SecondViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad];; 23 | _scrollview.contentSize = CGSizeMake(_scrollview.frame.size.width, 1000); 24 | _textField.sn_keyboardManagerEnabled = YES; 25 | _textField.sn_autoAdjustFrameEnabled = YES; 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/TableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewController.h 3 | // SNKeyboardManagerDemo 4 | // 5 | // Created by 苏合 on 16/2/15. 6 | // Copyright © 2016年 juangua. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TableViewController : UITableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/TableViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewController.m 3 | // SNKeyboardManagerDemo 4 | // 5 | // Created by 苏合 on 16/2/15. 6 | // Copyright © 2016年 juangua. All rights reserved. 7 | // 8 | 9 | #import "TableViewController.h" 10 | 11 | @implementation TableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // SNKeyboardManagerDemo 4 | // 5 | // Created by 苏合 on 16/2/14. 6 | // Copyright © 2016年 juangua. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // SNKeyboardManagerDemo 4 | // 5 | // Created by 苏合 on 16/2/14. 6 | // Copyright © 2016年 juangua. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "UITextField+SNKeyboardManager.h" 11 | #import "UITextView+SNKeyboardManager.h" 12 | 13 | @interface ViewController () 14 | 15 | @property (weak, nonatomic) IBOutlet UITextField *textField; 16 | @property (weak, nonatomic) IBOutlet UITextView *textView; 17 | @property (weak, nonatomic) IBOutlet UITextField *textField2; 18 | 19 | @end 20 | 21 | @implementation ViewController 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | _textField.sn_keyboardManagerEnabled = YES; 26 | _textField.sn_autoAdjustFrameEnabled = YES; 27 | _textView.sn_keyboardManagerEnabled = YES; 28 | _textField2.sn_keyboardManagerEnabled = YES; 29 | _textField2.sn_autoAdjustFrameEnabled = YES; 30 | } 31 | 32 | - (void)didReceiveMemoryWarning { 33 | [super didReceiveMemoryWarning]; 34 | // Dispose of any resources that can be recreated. 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SNKeyboardManagerDemo 4 | // 5 | // Created by 苏合 on 16/2/14. 6 | // Copyright © 2016年 juangua. 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 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemoTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /SNKeyboardManagerDemoTests/SNKeyboardManagerDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // SNKeyboardManagerDemoTests.m 3 | // SNKeyboardManagerDemoTests 4 | // 5 | // Created by 苏合 on 16/2/14. 6 | // Copyright © 2016年 juangua. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SNKeyboardManagerDemoTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation SNKeyboardManagerDemoTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /screenshot1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiaopen/SNKeyBoardManager/4bd0502cc84a07ab45a1f61ca253cf66dc593e82/screenshot1.gif -------------------------------------------------------------------------------- /screenshot2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiaopen/SNKeyBoardManager/4bd0502cc84a07ab45a1f61ca253cf66dc593e82/screenshot2.gif --------------------------------------------------------------------------------