├── .gitignore ├── .travis.yml ├── Demo ├── YYKeyboardManagerDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── YYKeyboardManagerDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ └── main.m └── snapshot.gif ├── Framework ├── Info.plist └── YYKeyboardManager.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── YYKeyboardManager.xcscheme ├── LICENSE ├── README.md ├── YYKeyboardManager.podspec └── YYKeyboardManager ├── YYKeyboardManager.h └── YYKeyboardManager.m /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | # 6 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 7 | 8 | ## Build generated 9 | build/ 10 | DerivedData/ 11 | 12 | ## Various settings 13 | *.pbxuser 14 | !default.pbxuser 15 | *.mode1v3 16 | !default.mode1v3 17 | *.mode2v3 18 | !default.mode2v3 19 | *.perspectivev3 20 | !default.perspectivev3 21 | xcuserdata/ 22 | 23 | ## Other 24 | *.moved-aside 25 | *.xccheckout 26 | *.xcuserstate 27 | *.xcscmblueprint 28 | 29 | ## Obj-C/Swift specific 30 | *.hmap 31 | *.ipa 32 | *.dSYM.zip 33 | *.dSYM 34 | 35 | # CocoaPods 36 | # 37 | # We recommend against adding the Pods directory to your .gitignore. However 38 | # you should judge for yourself, the pros and cons are mentioned at: 39 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 40 | # 41 | # Pods/ 42 | 43 | # Carthage 44 | # 45 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 46 | # Carthage/Checkouts 47 | 48 | Carthage/Build 49 | 50 | # fastlane 51 | # 52 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 53 | # screenshots whenever they are needed. 54 | # For more information about the recommended setup visit: 55 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 56 | 57 | fastlane/report.xml 58 | fastlane/Preview.html 59 | fastlane/screenshots 60 | fastlane/test_output 61 | 62 | # Code Injection 63 | # 64 | # After new code Injection tools there's a generated folder /iOSInjectionProject 65 | # https://github.com/johnno1962/injectionforxcode 66 | 67 | iOSInjectionProject/ 68 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | osx_image: xcode8 3 | xcode_project: Framework/YYKeyboardManager.xcodeproj 4 | xcode_scheme: YYKeyboardManager 5 | 6 | before_install: 7 | - env 8 | - xcodebuild -version 9 | - xcodebuild -showsdks 10 | - xcpretty --version 11 | 12 | script: 13 | - set -o pipefail 14 | - xcodebuild clean build -project "$TRAVIS_XCODE_PROJECT" -scheme "$TRAVIS_XCODE_SCHEME" | xcpretty 15 | -------------------------------------------------------------------------------- /Demo/YYKeyboardManagerDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D96891641F09024500ACB9F4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D96891631F09024500ACB9F4 /* AppDelegate.m */; }; 11 | D96891671F09024500ACB9F4 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D96891661F09024500ACB9F4 /* ViewController.m */; }; 12 | D968916A1F09024500ACB9F4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D96891681F09024500ACB9F4 /* Main.storyboard */; }; 13 | D968916C1F09024500ACB9F4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D968916B1F09024500ACB9F4 /* Assets.xcassets */; }; 14 | D968916F1F09024500ACB9F4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D968916D1F09024500ACB9F4 /* LaunchScreen.storyboard */; }; 15 | D96891721F09024500ACB9F4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D96891711F09024500ACB9F4 /* main.m */; }; 16 | D99DCC961F090277007143AB /* YYKeyboardManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D99DCC951F090277007143AB /* YYKeyboardManager.m */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | D968915F1F09024500ACB9F4 /* YYKeyboardManagerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = YYKeyboardManagerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | D96891621F09024500ACB9F4 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 22 | D96891631F09024500ACB9F4 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 23 | D96891651F09024500ACB9F4 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 24 | D96891661F09024500ACB9F4 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 25 | D96891691F09024500ACB9F4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 26 | D968916B1F09024500ACB9F4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 27 | D968916E1F09024500ACB9F4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 28 | D96891701F09024500ACB9F4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 29 | D96891711F09024500ACB9F4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 30 | D99DCC941F090277007143AB /* YYKeyboardManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YYKeyboardManager.h; sourceTree = ""; }; 31 | D99DCC951F090277007143AB /* YYKeyboardManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YYKeyboardManager.m; sourceTree = ""; }; 32 | /* End PBXFileReference section */ 33 | 34 | /* Begin PBXFrameworksBuildPhase section */ 35 | D968915C1F09024500ACB9F4 /* Frameworks */ = { 36 | isa = PBXFrameworksBuildPhase; 37 | buildActionMask = 2147483647; 38 | files = ( 39 | ); 40 | runOnlyForDeploymentPostprocessing = 0; 41 | }; 42 | /* End PBXFrameworksBuildPhase section */ 43 | 44 | /* Begin PBXGroup section */ 45 | D96891561F09024500ACB9F4 = { 46 | isa = PBXGroup; 47 | children = ( 48 | D99DCC931F090277007143AB /* YYKeyboardManager */, 49 | D96891611F09024500ACB9F4 /* YYKeyboardManagerDemo */, 50 | D96891601F09024500ACB9F4 /* Products */, 51 | ); 52 | sourceTree = ""; 53 | }; 54 | D96891601F09024500ACB9F4 /* Products */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | D968915F1F09024500ACB9F4 /* YYKeyboardManagerDemo.app */, 58 | ); 59 | name = Products; 60 | sourceTree = ""; 61 | }; 62 | D96891611F09024500ACB9F4 /* YYKeyboardManagerDemo */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | D96891621F09024500ACB9F4 /* AppDelegate.h */, 66 | D96891631F09024500ACB9F4 /* AppDelegate.m */, 67 | D96891651F09024500ACB9F4 /* ViewController.h */, 68 | D96891661F09024500ACB9F4 /* ViewController.m */, 69 | D96891681F09024500ACB9F4 /* Main.storyboard */, 70 | D968916B1F09024500ACB9F4 /* Assets.xcassets */, 71 | D968916D1F09024500ACB9F4 /* LaunchScreen.storyboard */, 72 | D96891701F09024500ACB9F4 /* Info.plist */, 73 | D96891711F09024500ACB9F4 /* main.m */, 74 | ); 75 | path = YYKeyboardManagerDemo; 76 | sourceTree = ""; 77 | }; 78 | D99DCC931F090277007143AB /* YYKeyboardManager */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | D99DCC941F090277007143AB /* YYKeyboardManager.h */, 82 | D99DCC951F090277007143AB /* YYKeyboardManager.m */, 83 | ); 84 | name = YYKeyboardManager; 85 | path = ../YYKeyboardManager; 86 | sourceTree = ""; 87 | }; 88 | /* End PBXGroup section */ 89 | 90 | /* Begin PBXNativeTarget section */ 91 | D968915E1F09024500ACB9F4 /* YYKeyboardManagerDemo */ = { 92 | isa = PBXNativeTarget; 93 | buildConfigurationList = D96891751F09024500ACB9F4 /* Build configuration list for PBXNativeTarget "YYKeyboardManagerDemo" */; 94 | buildPhases = ( 95 | D968915B1F09024500ACB9F4 /* Sources */, 96 | D968915C1F09024500ACB9F4 /* Frameworks */, 97 | D968915D1F09024500ACB9F4 /* Resources */, 98 | ); 99 | buildRules = ( 100 | ); 101 | dependencies = ( 102 | ); 103 | name = YYKeyboardManagerDemo; 104 | productName = YYKeyboardManagerDemo; 105 | productReference = D968915F1F09024500ACB9F4 /* YYKeyboardManagerDemo.app */; 106 | productType = "com.apple.product-type.application"; 107 | }; 108 | /* End PBXNativeTarget section */ 109 | 110 | /* Begin PBXProject section */ 111 | D96891571F09024500ACB9F4 /* Project object */ = { 112 | isa = PBXProject; 113 | attributes = { 114 | LastUpgradeCheck = 0900; 115 | ORGANIZATIONNAME = ibireme; 116 | TargetAttributes = { 117 | D968915E1F09024500ACB9F4 = { 118 | CreatedOnToolsVersion = 9.0; 119 | }; 120 | }; 121 | }; 122 | buildConfigurationList = D968915A1F09024500ACB9F4 /* Build configuration list for PBXProject "YYKeyboardManagerDemo" */; 123 | compatibilityVersion = "Xcode 8.0"; 124 | developmentRegion = en; 125 | hasScannedForEncodings = 0; 126 | knownRegions = ( 127 | en, 128 | Base, 129 | ); 130 | mainGroup = D96891561F09024500ACB9F4; 131 | productRefGroup = D96891601F09024500ACB9F4 /* Products */; 132 | projectDirPath = ""; 133 | projectRoot = ""; 134 | targets = ( 135 | D968915E1F09024500ACB9F4 /* YYKeyboardManagerDemo */, 136 | ); 137 | }; 138 | /* End PBXProject section */ 139 | 140 | /* Begin PBXResourcesBuildPhase section */ 141 | D968915D1F09024500ACB9F4 /* Resources */ = { 142 | isa = PBXResourcesBuildPhase; 143 | buildActionMask = 2147483647; 144 | files = ( 145 | D968916F1F09024500ACB9F4 /* LaunchScreen.storyboard in Resources */, 146 | D968916C1F09024500ACB9F4 /* Assets.xcassets in Resources */, 147 | D968916A1F09024500ACB9F4 /* Main.storyboard in Resources */, 148 | ); 149 | runOnlyForDeploymentPostprocessing = 0; 150 | }; 151 | /* End PBXResourcesBuildPhase section */ 152 | 153 | /* Begin PBXSourcesBuildPhase section */ 154 | D968915B1F09024500ACB9F4 /* Sources */ = { 155 | isa = PBXSourcesBuildPhase; 156 | buildActionMask = 2147483647; 157 | files = ( 158 | D99DCC961F090277007143AB /* YYKeyboardManager.m in Sources */, 159 | D96891671F09024500ACB9F4 /* ViewController.m in Sources */, 160 | D96891721F09024500ACB9F4 /* main.m in Sources */, 161 | D96891641F09024500ACB9F4 /* AppDelegate.m in Sources */, 162 | ); 163 | runOnlyForDeploymentPostprocessing = 0; 164 | }; 165 | /* End PBXSourcesBuildPhase section */ 166 | 167 | /* Begin PBXVariantGroup section */ 168 | D96891681F09024500ACB9F4 /* Main.storyboard */ = { 169 | isa = PBXVariantGroup; 170 | children = ( 171 | D96891691F09024500ACB9F4 /* Base */, 172 | ); 173 | name = Main.storyboard; 174 | sourceTree = ""; 175 | }; 176 | D968916D1F09024500ACB9F4 /* LaunchScreen.storyboard */ = { 177 | isa = PBXVariantGroup; 178 | children = ( 179 | D968916E1F09024500ACB9F4 /* Base */, 180 | ); 181 | name = LaunchScreen.storyboard; 182 | sourceTree = ""; 183 | }; 184 | /* End PBXVariantGroup section */ 185 | 186 | /* Begin XCBuildConfiguration section */ 187 | D96891731F09024500ACB9F4 /* Debug */ = { 188 | isa = XCBuildConfiguration; 189 | buildSettings = { 190 | ALWAYS_SEARCH_USER_PATHS = NO; 191 | CLANG_ANALYZER_NONNULL = YES; 192 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 193 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 194 | CLANG_CXX_LIBRARY = "libc++"; 195 | CLANG_ENABLE_MODULES = YES; 196 | CLANG_ENABLE_OBJC_ARC = YES; 197 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 198 | CLANG_WARN_BOOL_CONVERSION = YES; 199 | CLANG_WARN_COMMA = YES; 200 | CLANG_WARN_CONSTANT_CONVERSION = YES; 201 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 202 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 203 | CLANG_WARN_EMPTY_BODY = YES; 204 | CLANG_WARN_ENUM_CONVERSION = YES; 205 | CLANG_WARN_INFINITE_RECURSION = YES; 206 | CLANG_WARN_INT_CONVERSION = YES; 207 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 208 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 209 | CLANG_WARN_STRICT_PROTOTYPES = YES; 210 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 211 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 212 | CLANG_WARN_UNREACHABLE_CODE = YES; 213 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 214 | CODE_SIGN_IDENTITY = "iPhone Developer"; 215 | COPY_PHASE_STRIP = NO; 216 | DEBUG_INFORMATION_FORMAT = dwarf; 217 | ENABLE_STRICT_OBJC_MSGSEND = YES; 218 | ENABLE_TESTABILITY = YES; 219 | GCC_C_LANGUAGE_STANDARD = gnu11; 220 | GCC_DYNAMIC_NO_PIC = NO; 221 | GCC_NO_COMMON_BLOCKS = YES; 222 | GCC_OPTIMIZATION_LEVEL = 0; 223 | GCC_PREPROCESSOR_DEFINITIONS = ( 224 | "DEBUG=1", 225 | "$(inherited)", 226 | ); 227 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 228 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 229 | GCC_WARN_UNDECLARED_SELECTOR = YES; 230 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 231 | GCC_WARN_UNUSED_FUNCTION = YES; 232 | GCC_WARN_UNUSED_VARIABLE = YES; 233 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 234 | MTL_ENABLE_DEBUG_INFO = YES; 235 | ONLY_ACTIVE_ARCH = YES; 236 | SDKROOT = iphoneos; 237 | }; 238 | name = Debug; 239 | }; 240 | D96891741F09024500ACB9F4 /* Release */ = { 241 | isa = XCBuildConfiguration; 242 | buildSettings = { 243 | ALWAYS_SEARCH_USER_PATHS = NO; 244 | CLANG_ANALYZER_NONNULL = YES; 245 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 246 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 247 | CLANG_CXX_LIBRARY = "libc++"; 248 | CLANG_ENABLE_MODULES = YES; 249 | CLANG_ENABLE_OBJC_ARC = YES; 250 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 251 | CLANG_WARN_BOOL_CONVERSION = YES; 252 | CLANG_WARN_COMMA = YES; 253 | CLANG_WARN_CONSTANT_CONVERSION = YES; 254 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 255 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 256 | CLANG_WARN_EMPTY_BODY = YES; 257 | CLANG_WARN_ENUM_CONVERSION = YES; 258 | CLANG_WARN_INFINITE_RECURSION = YES; 259 | CLANG_WARN_INT_CONVERSION = YES; 260 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 261 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 262 | CLANG_WARN_STRICT_PROTOTYPES = YES; 263 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 264 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 265 | CLANG_WARN_UNREACHABLE_CODE = YES; 266 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 267 | CODE_SIGN_IDENTITY = "iPhone Developer"; 268 | COPY_PHASE_STRIP = NO; 269 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 270 | ENABLE_NS_ASSERTIONS = NO; 271 | ENABLE_STRICT_OBJC_MSGSEND = YES; 272 | GCC_C_LANGUAGE_STANDARD = gnu11; 273 | GCC_NO_COMMON_BLOCKS = YES; 274 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 275 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 276 | GCC_WARN_UNDECLARED_SELECTOR = YES; 277 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 278 | GCC_WARN_UNUSED_FUNCTION = YES; 279 | GCC_WARN_UNUSED_VARIABLE = YES; 280 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 281 | MTL_ENABLE_DEBUG_INFO = NO; 282 | SDKROOT = iphoneos; 283 | VALIDATE_PRODUCT = YES; 284 | }; 285 | name = Release; 286 | }; 287 | D96891761F09024500ACB9F4 /* Debug */ = { 288 | isa = XCBuildConfiguration; 289 | buildSettings = { 290 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 291 | INFOPLIST_FILE = YYKeyboardManagerDemo/Info.plist; 292 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 293 | PRODUCT_BUNDLE_IDENTIFIER = com.ibireme.YYKeyboardManagerDemo; 294 | PRODUCT_NAME = "$(TARGET_NAME)"; 295 | TARGETED_DEVICE_FAMILY = "1,2"; 296 | }; 297 | name = Debug; 298 | }; 299 | D96891771F09024500ACB9F4 /* Release */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 303 | INFOPLIST_FILE = YYKeyboardManagerDemo/Info.plist; 304 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 305 | PRODUCT_BUNDLE_IDENTIFIER = com.ibireme.YYKeyboardManagerDemo; 306 | PRODUCT_NAME = "$(TARGET_NAME)"; 307 | TARGETED_DEVICE_FAMILY = "1,2"; 308 | }; 309 | name = Release; 310 | }; 311 | /* End XCBuildConfiguration section */ 312 | 313 | /* Begin XCConfigurationList section */ 314 | D968915A1F09024500ACB9F4 /* Build configuration list for PBXProject "YYKeyboardManagerDemo" */ = { 315 | isa = XCConfigurationList; 316 | buildConfigurations = ( 317 | D96891731F09024500ACB9F4 /* Debug */, 318 | D96891741F09024500ACB9F4 /* Release */, 319 | ); 320 | defaultConfigurationIsVisible = 0; 321 | defaultConfigurationName = Release; 322 | }; 323 | D96891751F09024500ACB9F4 /* Build configuration list for PBXNativeTarget "YYKeyboardManagerDemo" */ = { 324 | isa = XCConfigurationList; 325 | buildConfigurations = ( 326 | D96891761F09024500ACB9F4 /* Debug */, 327 | D96891771F09024500ACB9F4 /* Release */, 328 | ); 329 | defaultConfigurationIsVisible = 0; 330 | defaultConfigurationName = Release; 331 | }; 332 | /* End XCConfigurationList section */ 333 | }; 334 | rootObject = D96891571F09024500ACB9F4 /* Project object */; 335 | } 336 | -------------------------------------------------------------------------------- /Demo/YYKeyboardManagerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Demo/YYKeyboardManagerDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // YYKeyboardManagerDemo 4 | // 5 | // Created by ibireme on 15/10/14. 6 | // Copyright © 2015 ibireme. 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 | -------------------------------------------------------------------------------- /Demo/YYKeyboardManagerDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // YYKeyboardManagerDemo 4 | // 5 | // Created by ibireme on 15/10/14. 6 | // Copyright © 2015 ibireme. 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 | -------------------------------------------------------------------------------- /Demo/YYKeyboardManagerDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /Demo/YYKeyboardManagerDemo/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 | -------------------------------------------------------------------------------- /Demo/YYKeyboardManagerDemo/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 | -------------------------------------------------------------------------------- /Demo/YYKeyboardManagerDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 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 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Demo/YYKeyboardManagerDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // YYKeyboardManagerDemo 4 | // 5 | // Created by ibireme on 15/10/14. 6 | // Copyright © 2015 ibireme. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /Demo/YYKeyboardManagerDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // YYKeyboardManagerDemo 4 | // 5 | // Created by ibireme on 15/10/14. 6 | // Copyright © 2015 ibireme. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "YYKeyboardManager.h" 11 | 12 | @interface ViewController () 13 | @property (nonatomic, strong) UITextField *textField; 14 | @property (nonatomic, strong) UIButton *button; 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | 22 | 23 | _button = [UIButton buttonWithType:UIButtonTypeCustom]; 24 | _button.frame = CGRectMake(0, 0, 80, 40); 25 | _button.center = CGPointMake(CGRectGetWidth(self.view.bounds) / 2, CGRectGetHeight(self.view.bounds) / 3); 26 | _button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 27 | [_button addTarget:self action:@selector(buttonTapped) forControlEvents:UIControlEventTouchUpInside]; 28 | [_button setTitle:@"Toggle" forState:UIControlStateNormal]; 29 | [_button setTitleColor:[UIColor colorWithRed:0.062 green:0.518 blue:0.998 alpha:1.000] forState:UIControlStateNormal]; 30 | [self.view addSubview:_button]; 31 | 32 | _textField = [UITextField new]; 33 | _textField.backgroundColor = [UIColor colorWithRed:0.791 green:0.861 blue:0.999 alpha:1.000]; 34 | _textField.placeholder = @" Tap to show keyboard. "; 35 | CGRect frame = CGRectZero; 36 | frame.size.width = self.view.frame.size.width; 37 | frame.size.height = 40; 38 | frame.origin.y = self.view.frame.size.height - frame.size.height; 39 | _textField.frame = frame; 40 | _textField.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; 41 | [self.view addSubview:_textField]; 42 | 43 | 44 | 45 | 46 | [[YYKeyboardManager defaultManager] addObserver:self]; 47 | } 48 | 49 | - (void)dealloc { 50 | [[YYKeyboardManager defaultManager] removeObserver:self]; 51 | } 52 | 53 | - (void)buttonTapped { 54 | if (_textField.isFirstResponder) { 55 | [_textField resignFirstResponder]; 56 | } else { 57 | [_textField becomeFirstResponder]; 58 | } 59 | } 60 | 61 | #pragma mark - @protocol YYKeyboardObserver 62 | 63 | - (void)keyboardChangedWithTransition:(YYKeyboardTransition)transition { 64 | [UIView animateWithDuration:transition.animationDuration delay:0 options:transition.animationOption animations:^{ 65 | CGRect kbFrame = [[YYKeyboardManager defaultManager] convertRect:transition.toFrame toView:self.view]; 66 | CGRect textframe = _textField.frame; 67 | textframe.size.width = kbFrame.size.width; 68 | textframe.origin.y = kbFrame.origin.y - textframe.size.height; 69 | _textField.frame = textframe; 70 | } completion:^(BOOL finished) { 71 | 72 | }]; 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /Demo/YYKeyboardManagerDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // YYKeyboardManagerDemo 4 | // 5 | // Created by ibireme on 15/10/14. 6 | // Copyright © 2015 ibireme. 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 | -------------------------------------------------------------------------------- /Demo/snapshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibireme/YYKeyboardManager/92b84d8cc1c27e17703b4bdb0aecddf80723a158/Demo/snapshot.gif -------------------------------------------------------------------------------- /Framework/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.1 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Framework/YYKeyboardManager.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D9045AC51F06A2770075FB54 /* YYKeyboardManager.h in Headers */ = {isa = PBXBuildFile; fileRef = D9045AC31F06A2770075FB54 /* YYKeyboardManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | D9045AC61F06A2770075FB54 /* YYKeyboardManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D9045AC41F06A2770075FB54 /* YYKeyboardManager.m */; }; 12 | /* End PBXBuildFile section */ 13 | 14 | /* Begin PBXFileReference section */ 15 | D9045AC31F06A2770075FB54 /* YYKeyboardManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YYKeyboardManager.h; sourceTree = ""; }; 16 | D9045AC41F06A2770075FB54 /* YYKeyboardManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YYKeyboardManager.m; sourceTree = ""; }; 17 | D90545F01F06A23E00D946CB /* YYKeyboardManager.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = YYKeyboardManager.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 18 | D90545F41F06A23E00D946CB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = ../Framework/Info.plist; sourceTree = ""; }; 19 | /* End PBXFileReference section */ 20 | 21 | /* Begin PBXFrameworksBuildPhase section */ 22 | D90545EC1F06A23E00D946CB /* Frameworks */ = { 23 | isa = PBXFrameworksBuildPhase; 24 | buildActionMask = 2147483647; 25 | files = ( 26 | ); 27 | runOnlyForDeploymentPostprocessing = 0; 28 | }; 29 | /* End PBXFrameworksBuildPhase section */ 30 | 31 | /* Begin PBXGroup section */ 32 | D9045AC21F06A2770075FB54 /* YYKeyboardManager */ = { 33 | isa = PBXGroup; 34 | children = ( 35 | D9045AC31F06A2770075FB54 /* YYKeyboardManager.h */, 36 | D9045AC41F06A2770075FB54 /* YYKeyboardManager.m */, 37 | D90545F41F06A23E00D946CB /* Info.plist */, 38 | ); 39 | name = YYKeyboardManager; 40 | path = ../YYKeyboardManager; 41 | sourceTree = ""; 42 | }; 43 | D90545E61F06A23E00D946CB = { 44 | isa = PBXGroup; 45 | children = ( 46 | D9045AC21F06A2770075FB54 /* YYKeyboardManager */, 47 | D90545F11F06A23E00D946CB /* Products */, 48 | ); 49 | sourceTree = ""; 50 | }; 51 | D90545F11F06A23E00D946CB /* Products */ = { 52 | isa = PBXGroup; 53 | children = ( 54 | D90545F01F06A23E00D946CB /* YYKeyboardManager.framework */, 55 | ); 56 | name = Products; 57 | sourceTree = ""; 58 | }; 59 | /* End PBXGroup section */ 60 | 61 | /* Begin PBXHeadersBuildPhase section */ 62 | D90545ED1F06A23E00D946CB /* Headers */ = { 63 | isa = PBXHeadersBuildPhase; 64 | buildActionMask = 2147483647; 65 | files = ( 66 | D9045AC51F06A2770075FB54 /* YYKeyboardManager.h in Headers */, 67 | ); 68 | runOnlyForDeploymentPostprocessing = 0; 69 | }; 70 | /* End PBXHeadersBuildPhase section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | D90545EF1F06A23E00D946CB /* YYKeyboardManager */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = D90545F81F06A23E00D946CB /* Build configuration list for PBXNativeTarget "YYKeyboardManager" */; 76 | buildPhases = ( 77 | D90545EB1F06A23E00D946CB /* Sources */, 78 | D90545EC1F06A23E00D946CB /* Frameworks */, 79 | D90545ED1F06A23E00D946CB /* Headers */, 80 | D90545EE1F06A23E00D946CB /* Resources */, 81 | ); 82 | buildRules = ( 83 | ); 84 | dependencies = ( 85 | ); 86 | name = YYKeyboardManager; 87 | productName = YYKeyboardManager; 88 | productReference = D90545F01F06A23E00D946CB /* YYKeyboardManager.framework */; 89 | productType = "com.apple.product-type.framework"; 90 | }; 91 | /* End PBXNativeTarget section */ 92 | 93 | /* Begin PBXProject section */ 94 | D90545E71F06A23E00D946CB /* Project object */ = { 95 | isa = PBXProject; 96 | attributes = { 97 | LastUpgradeCheck = 0900; 98 | ORGANIZATIONNAME = ibireme; 99 | TargetAttributes = { 100 | D90545EF1F06A23E00D946CB = { 101 | CreatedOnToolsVersion = 9.0; 102 | }; 103 | }; 104 | }; 105 | buildConfigurationList = D90545EA1F06A23E00D946CB /* Build configuration list for PBXProject "YYKeyboardManager" */; 106 | compatibilityVersion = "Xcode 8.0"; 107 | developmentRegion = en; 108 | hasScannedForEncodings = 0; 109 | knownRegions = ( 110 | en, 111 | ); 112 | mainGroup = D90545E61F06A23E00D946CB; 113 | productRefGroup = D90545F11F06A23E00D946CB /* Products */; 114 | projectDirPath = ""; 115 | projectRoot = ""; 116 | targets = ( 117 | D90545EF1F06A23E00D946CB /* YYKeyboardManager */, 118 | ); 119 | }; 120 | /* End PBXProject section */ 121 | 122 | /* Begin PBXResourcesBuildPhase section */ 123 | D90545EE1F06A23E00D946CB /* Resources */ = { 124 | isa = PBXResourcesBuildPhase; 125 | buildActionMask = 2147483647; 126 | files = ( 127 | ); 128 | runOnlyForDeploymentPostprocessing = 0; 129 | }; 130 | /* End PBXResourcesBuildPhase section */ 131 | 132 | /* Begin PBXSourcesBuildPhase section */ 133 | D90545EB1F06A23E00D946CB /* Sources */ = { 134 | isa = PBXSourcesBuildPhase; 135 | buildActionMask = 2147483647; 136 | files = ( 137 | D9045AC61F06A2770075FB54 /* YYKeyboardManager.m in Sources */, 138 | ); 139 | runOnlyForDeploymentPostprocessing = 0; 140 | }; 141 | /* End PBXSourcesBuildPhase section */ 142 | 143 | /* Begin XCBuildConfiguration section */ 144 | D90545F61F06A23E00D946CB /* Debug */ = { 145 | isa = XCBuildConfiguration; 146 | buildSettings = { 147 | ALWAYS_SEARCH_USER_PATHS = NO; 148 | CLANG_ANALYZER_NONNULL = YES; 149 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 150 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 151 | CLANG_CXX_LIBRARY = "libc++"; 152 | CLANG_ENABLE_MODULES = YES; 153 | CLANG_ENABLE_OBJC_ARC = YES; 154 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 155 | CLANG_WARN_BOOL_CONVERSION = YES; 156 | CLANG_WARN_COMMA = YES; 157 | CLANG_WARN_CONSTANT_CONVERSION = YES; 158 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 159 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 160 | CLANG_WARN_EMPTY_BODY = YES; 161 | CLANG_WARN_ENUM_CONVERSION = YES; 162 | CLANG_WARN_INFINITE_RECURSION = YES; 163 | CLANG_WARN_INT_CONVERSION = YES; 164 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 165 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 166 | CLANG_WARN_STRICT_PROTOTYPES = YES; 167 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 168 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 169 | CLANG_WARN_UNREACHABLE_CODE = YES; 170 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 171 | CODE_SIGN_IDENTITY = "iPhone Developer"; 172 | COPY_PHASE_STRIP = NO; 173 | CURRENT_PROJECT_VERSION = 1; 174 | DEBUG_INFORMATION_FORMAT = dwarf; 175 | ENABLE_STRICT_OBJC_MSGSEND = YES; 176 | ENABLE_TESTABILITY = YES; 177 | GCC_C_LANGUAGE_STANDARD = gnu11; 178 | GCC_DYNAMIC_NO_PIC = NO; 179 | GCC_NO_COMMON_BLOCKS = YES; 180 | GCC_OPTIMIZATION_LEVEL = 0; 181 | GCC_PREPROCESSOR_DEFINITIONS = ( 182 | "DEBUG=1", 183 | "$(inherited)", 184 | ); 185 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 186 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 187 | GCC_WARN_UNDECLARED_SELECTOR = YES; 188 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 189 | GCC_WARN_UNUSED_FUNCTION = YES; 190 | GCC_WARN_UNUSED_VARIABLE = YES; 191 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 192 | MTL_ENABLE_DEBUG_INFO = YES; 193 | ONLY_ACTIVE_ARCH = YES; 194 | SDKROOT = iphoneos; 195 | VERSIONING_SYSTEM = "apple-generic"; 196 | VERSION_INFO_PREFIX = ""; 197 | }; 198 | name = Debug; 199 | }; 200 | D90545F71F06A23E00D946CB /* Release */ = { 201 | isa = XCBuildConfiguration; 202 | buildSettings = { 203 | ALWAYS_SEARCH_USER_PATHS = NO; 204 | CLANG_ANALYZER_NONNULL = YES; 205 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 206 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 207 | CLANG_CXX_LIBRARY = "libc++"; 208 | CLANG_ENABLE_MODULES = YES; 209 | CLANG_ENABLE_OBJC_ARC = YES; 210 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 211 | CLANG_WARN_BOOL_CONVERSION = YES; 212 | CLANG_WARN_COMMA = YES; 213 | CLANG_WARN_CONSTANT_CONVERSION = YES; 214 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 215 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 216 | CLANG_WARN_EMPTY_BODY = YES; 217 | CLANG_WARN_ENUM_CONVERSION = YES; 218 | CLANG_WARN_INFINITE_RECURSION = YES; 219 | CLANG_WARN_INT_CONVERSION = YES; 220 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 221 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 222 | CLANG_WARN_STRICT_PROTOTYPES = YES; 223 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 224 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 225 | CLANG_WARN_UNREACHABLE_CODE = YES; 226 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 227 | CODE_SIGN_IDENTITY = "iPhone Developer"; 228 | COPY_PHASE_STRIP = NO; 229 | CURRENT_PROJECT_VERSION = 1; 230 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 231 | ENABLE_NS_ASSERTIONS = NO; 232 | ENABLE_STRICT_OBJC_MSGSEND = YES; 233 | GCC_C_LANGUAGE_STANDARD = gnu11; 234 | GCC_NO_COMMON_BLOCKS = YES; 235 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 236 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 237 | GCC_WARN_UNDECLARED_SELECTOR = YES; 238 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 239 | GCC_WARN_UNUSED_FUNCTION = YES; 240 | GCC_WARN_UNUSED_VARIABLE = YES; 241 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 242 | MTL_ENABLE_DEBUG_INFO = NO; 243 | SDKROOT = iphoneos; 244 | VALIDATE_PRODUCT = YES; 245 | VERSIONING_SYSTEM = "apple-generic"; 246 | VERSION_INFO_PREFIX = ""; 247 | }; 248 | name = Release; 249 | }; 250 | D90545F91F06A23E00D946CB /* Debug */ = { 251 | isa = XCBuildConfiguration; 252 | buildSettings = { 253 | CODE_SIGN_IDENTITY = ""; 254 | DEFINES_MODULE = YES; 255 | DYLIB_COMPATIBILITY_VERSION = 1; 256 | DYLIB_CURRENT_VERSION = 1; 257 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 258 | INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; 259 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 260 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 261 | PRODUCT_BUNDLE_IDENTIFIER = com.ibireme.YYKeyboardManager; 262 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 263 | SKIP_INSTALL = YES; 264 | TARGETED_DEVICE_FAMILY = "1,2"; 265 | }; 266 | name = Debug; 267 | }; 268 | D90545FA1F06A23E00D946CB /* Release */ = { 269 | isa = XCBuildConfiguration; 270 | buildSettings = { 271 | CODE_SIGN_IDENTITY = ""; 272 | DEFINES_MODULE = YES; 273 | DYLIB_COMPATIBILITY_VERSION = 1; 274 | DYLIB_CURRENT_VERSION = 1; 275 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 276 | INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; 277 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 278 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 279 | PRODUCT_BUNDLE_IDENTIFIER = com.ibireme.YYKeyboardManager; 280 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 281 | SKIP_INSTALL = YES; 282 | TARGETED_DEVICE_FAMILY = "1,2"; 283 | }; 284 | name = Release; 285 | }; 286 | /* End XCBuildConfiguration section */ 287 | 288 | /* Begin XCConfigurationList section */ 289 | D90545EA1F06A23E00D946CB /* Build configuration list for PBXProject "YYKeyboardManager" */ = { 290 | isa = XCConfigurationList; 291 | buildConfigurations = ( 292 | D90545F61F06A23E00D946CB /* Debug */, 293 | D90545F71F06A23E00D946CB /* Release */, 294 | ); 295 | defaultConfigurationIsVisible = 0; 296 | defaultConfigurationName = Release; 297 | }; 298 | D90545F81F06A23E00D946CB /* Build configuration list for PBXNativeTarget "YYKeyboardManager" */ = { 299 | isa = XCConfigurationList; 300 | buildConfigurations = ( 301 | D90545F91F06A23E00D946CB /* Debug */, 302 | D90545FA1F06A23E00D946CB /* Release */, 303 | ); 304 | defaultConfigurationIsVisible = 0; 305 | defaultConfigurationName = Release; 306 | }; 307 | /* End XCConfigurationList section */ 308 | }; 309 | rootObject = D90545E71F06A23E00D946CB /* Project object */; 310 | } 311 | -------------------------------------------------------------------------------- /Framework/YYKeyboardManager.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Framework/YYKeyboardManager.xcodeproj/xcshareddata/xcschemes/YYKeyboardManager.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 35 | 36 | 46 | 47 | 53 | 54 | 55 | 56 | 57 | 58 | 64 | 65 | 71 | 72 | 73 | 74 | 76 | 77 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 ibireme 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | YYKeyboardManager 2 | ============== 3 | 4 | [![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/ibireme/YYKeyboardManager/master/LICENSE)  5 | [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)  6 | [![CocoaPods](http://img.shields.io/cocoapods/v/YYKeyboardManager.svg?style=flat)](http://cocoapods.org/pods/YYKeyboardManager)  7 | [![CocoaPods](http://img.shields.io/cocoapods/p/YYKeyboardManager.svg?style=flat)](http://cocoadocs.org/docsets/YYKeyboardManager)  8 | [![Support](https://img.shields.io/badge/support-iOS%206%2B%20-blue.svg?style=flat)](https://www.apple.com/nl/ios/)  9 | [![Build Status](https://travis-ci.org/ibireme/YYKeyboardManager.svg?branch=master)](https://travis-ci.org/ibireme/YYKeyboardManager) 10 | 11 | iOS utility class allows you to access keyboard view and track keyboard animation.
12 | (It was used by [YYText](https://github.com/ibireme/YYText)) 13 | 14 | > ![demo](https://raw.github.com/ibireme/YYKeyboardManager/master/Demo/snapshot.gif 15 | ) 16 | 17 | Compatibility 18 | ============== 19 | iPhone / iPad / iPod with iOS 6~11. 20 | 21 | 22 | Usage 23 | ============== 24 | ```objc 25 | // Get keyboard manager 26 | YYKeyboardManager *manager = [YYKeyboardManager defaultManager]; 27 | 28 | // Get keyboard view and window 29 | UIView *view = manager.keyboardView; 30 | UIWindow *window = manager.keyboardWindow; 31 | 32 | // Get keyboard status 33 | BOOL visible = manager.keyboardVisible; 34 | CGRect frame = manager.keyboardFrame; 35 | frame = [manager convertRect:frame toView:self.view]; 36 | 37 | // Track keyboard animation 38 | [manager addObserver:self]; 39 | - (void)keyboardChangedWithTransition:(YYKeyboardTransition)transition { 40 | CGRect fromFrame = [manager convertRect:transition.fromFrame toView:self.view]; 41 | CGRect toFrame = [manager convertRect:transition.toFrame toView:self.view]; 42 | BOOL fromVisible = transition.fromVisible; 43 | BOOL toVisible = transition.toVisible; 44 | NSTimeInterval animationDuration = transition.animationDuration; 45 | UIViewAnimationCurve curve = transition.animationCurve; 46 | } 47 | ``` 48 | 49 | Installation 50 | ============== 51 | 52 | ### CocoaPods 53 | 54 | 1. Add `pod 'YYKeyboardManager'` to your Podfile. 55 | 2. Run `pod install` or `pod update`. 56 | 3. Import \. 57 | 58 | 59 | ### Carthage 60 | 61 | 1. Add `github "ibireme/YYKeyboardManager"` to your Cartfile. 62 | 2. Run `carthage update --platform ios` and add the framework to your project. 63 | 3. Import \. 64 | 65 | 66 | ### Manually 67 | 68 | 1. Download all the files in the YYKeyboardManager subdirectory. 69 | 2. Add the source files to your Xcode project. 70 | 3. Import `YYKeyboardManager.h`. 71 | 72 | 73 | Documentation 74 | ============== 75 | Full API documentation is available on [CocoaDocs](http://cocoadocs.org/docsets/YYKeyboardManager/).
76 | You can also install documentation locally using [appledoc](https://github.com/tomaz/appledoc). 77 | 78 | 79 | Requirements 80 | ============== 81 | This library requires `iOS 6.0+` and `Xcode 8.0+`. 82 | 83 | 84 | License 85 | ============== 86 | YYKeyboardManager is provided under the MIT license. See LICENSE file for details. 87 | 88 | 89 | 90 |

91 | --- 92 | 中文介绍 93 | ============== 94 | iOS 键盘监听管理工具类。
95 | (该工具是从 [YYText](https://github.com/ibireme/YYText) 提取出来的独立组件) 96 | 97 | > ![demo](https://raw.github.com/ibireme/YYKeyboardManager/master/Demo/snapshot.gif 98 | ) 99 | 100 | 兼容性 101 | ============== 102 | 该项目能很好的兼容 iPhone / iPad / iPod,兼容 iOS 6~11, 103 | 并且能很好的处理屏幕旋转。 104 | 105 | 用法 106 | ============== 107 | ```objc 108 | // 获取键盘管理器 109 | YYKeyboardManager *manager = [YYKeyboardManager defaultManager]; 110 | 111 | // 获取键盘的 view 和 window 112 | UIView *view = manager.keyboardView; 113 | UIWindow *window = manager.keyboardWindow; 114 | 115 | // 获取键盘当前状态 116 | BOOL visible = manager.keyboardVisible; 117 | CGRect frame = manager.keyboardFrame; 118 | frame = [manager convertRect:frame toView:self.view]; 119 | 120 | // 监听键盘动画 121 | [manager addObserver:self]; 122 | - (void)keyboardChangedWithTransition:(YYKeyboardTransition)transition { 123 | CGRect fromFrame = [manager convertRect:transition.fromFrame toView:self.view]; 124 | CGRect toFrame = [manager convertRect:transition.toFrame toView:self.view]; 125 | BOOL fromVisible = transition.fromVisible; 126 | BOOL toVisible = transition.toVisible; 127 | NSTimeInterval animationDuration = transition.animationDuration; 128 | UIViewAnimationCurve curve = transition.animationCurve; 129 | } 130 | ``` 131 | 132 | 安装 133 | ============== 134 | 135 | ### CocoaPods 136 | 137 | 1. 在 Podfile 中添加 `pod 'YYKeyboardManager'`。 138 | 2. 执行 `pod install` 或 `pod update`。 139 | 3. 导入 \。 140 | 141 | 142 | ### Carthage 143 | 144 | 1. 在 Cartfile 中添加 `github "ibireme/YYKeyboardManager"`。 145 | 2. 执行 `carthage update --platform ios` 并将生成的 framework 添加到你的工程。 146 | 3. 导入 \。 147 | 148 | 149 | ### 手动安装 150 | 151 | 1. 下载 YYKeyboardManager 文件夹内的所有内容。 152 | 2. 将 YYKeyboardManager 内的源文件添加(拖放)到你的工程。 153 | 3. 导入 `YYKeyboardManager.h`。 154 | 155 | 156 | 文档 157 | ============== 158 | 你可以在 [CocoaDocs](http://cocoadocs.org/docsets/YYKeyboardManager/) 查看在线 API 文档,也可以用 [appledoc](https://github.com/tomaz/appledoc) 本地生成文档。 159 | 160 | 161 | 系统要求 162 | ============== 163 | 该项目最低支持 `iOS 6.0` 和 `Xcode 8.0`。 164 | 165 | 166 | 许可证 167 | ============== 168 | YYKeyboardManager 使用 MIT 许可证,详情见 LICENSE 文件。 169 | 170 | 171 | -------------------------------------------------------------------------------- /YYKeyboardManager.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'YYKeyboardManager' 3 | s.summary = 'iOS utility class allows you to access keyboard view and track keyboard animation.' 4 | s.version = '1.0.1' 5 | s.license = { :type => 'MIT', :file => 'LICENSE' } 6 | s.authors = { 'ibireme' => 'ibireme@gmail.com' } 7 | s.social_media_url = 'http://blog.ibireme.com' 8 | s.homepage = 'https://github.com/ibireme/YYKeyboardManager' 9 | s.platform = :ios, '6.0' 10 | s.ios.deployment_target = '6.0' 11 | s.source = { :git => 'https://github.com/ibireme/YYKeyboardManager.git', :tag => s.version.to_s } 12 | 13 | s.requires_arc = true 14 | s.source_files = 'YYKeyboardManager/*.{h,m}' 15 | s.public_header_files = 'YYKeyboardManager/*.{h}' 16 | 17 | s.frameworks = 'UIKit' 18 | 19 | end 20 | -------------------------------------------------------------------------------- /YYKeyboardManager/YYKeyboardManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // YYKeyboardManager.h 3 | // YYKit 4 | // 5 | // Created by ibireme on 15/6/3. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import 13 | 14 | #if __has_include() 15 | FOUNDATION_EXPORT double YYKeyboardManagerVersionNumber; 16 | FOUNDATION_EXPORT const unsigned char YYKeyboardManagerVersionString[]; 17 | #endif 18 | 19 | NS_ASSUME_NONNULL_BEGIN 20 | 21 | /** 22 | System keyboard transition information. 23 | Use -[YYKeyboardManager convertRect:toView:] to convert frame to specified view. 24 | */ 25 | typedef struct { 26 | BOOL fromVisible; ///< Keyboard visible before transition. 27 | BOOL toVisible; ///< Keyboard visible after transition. 28 | CGRect fromFrame; ///< Keyboard frame before transition. 29 | CGRect toFrame; ///< Keyboard frame after transition. 30 | NSTimeInterval animationDuration; ///< Keyboard transition animation duration. 31 | UIViewAnimationCurve animationCurve; ///< Keyboard transition animation curve. 32 | UIViewAnimationOptions animationOption; ///< Keybaord transition animation option. 33 | } YYKeyboardTransition; 34 | 35 | 36 | /** 37 | The YYKeyboardObserver protocol defines the method you can use 38 | to receive system keyboard change information. 39 | */ 40 | @protocol YYKeyboardObserver 41 | @optional 42 | - (void)keyboardChangedWithTransition:(YYKeyboardTransition)transition; 43 | @end 44 | 45 | 46 | /** 47 | A YYKeyboardManager object lets you get the system keyboard information, 48 | and track the keyboard visible/frame/transition. 49 | 50 | @discussion You should access this class in main thread. 51 | Compatible: iPhone/iPad with iOS6/7/8/9. 52 | */ 53 | @interface YYKeyboardManager : NSObject 54 | 55 | - (instancetype)init UNAVAILABLE_ATTRIBUTE; 56 | + (instancetype)new UNAVAILABLE_ATTRIBUTE; 57 | 58 | /// Get the default manager. 59 | + (instancetype)defaultManager; 60 | 61 | /// Get the keyboard window. nil if there's no keyboard window. 62 | @property (nullable, nonatomic, readonly) UIWindow *keyboardWindow; 63 | 64 | /// Get the keyboard view. nil if there's no keyboard view. 65 | @property (nullable, nonatomic, readonly) UIView *keyboardView; 66 | 67 | /// Whether the keyboard is visible. 68 | @property (nonatomic, readonly, getter=isKeyboardVisible) BOOL keyboardVisible; 69 | 70 | /// Get the keyboard frame. CGRectNull if there's no keyboard view. 71 | /// Use convertRect:toView: to convert frame to specified view. 72 | @property (nonatomic, readonly) CGRect keyboardFrame; 73 | 74 | 75 | /** 76 | Add an observer to manager to get keyboard change information. 77 | This method makes a weak reference to the observer. 78 | 79 | @param observer An observer. 80 | This method will do nothing if the observer is nil, or already added. 81 | */ 82 | - (void)addObserver:(id)observer; 83 | 84 | /** 85 | Remove an observer from manager. 86 | 87 | @param observer An observer. 88 | This method will do nothing if the observer is nil, or not in manager. 89 | */ 90 | - (void)removeObserver:(id)observer; 91 | 92 | /** 93 | Convert rect to specified view or window. 94 | 95 | @param rect The frame rect. 96 | @param view A specified view or window (pass nil to convert for main window). 97 | @return The converted rect in specifeid view. 98 | */ 99 | - (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view; 100 | 101 | @end 102 | 103 | NS_ASSUME_NONNULL_END 104 | -------------------------------------------------------------------------------- /YYKeyboardManager/YYKeyboardManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // YYKeyboardManager.m 3 | // YYKit 4 | // 5 | // Created by ibireme on 15/6/3. 6 | // Copyright (c) 2015 ibireme. 7 | // 8 | // This source code is licensed under the MIT-style license found in the 9 | // LICENSE file in the root directory of this source tree. 10 | // 11 | 12 | #import "YYKeyboardManager.h" 13 | #import 14 | 15 | 16 | static int _YYKeyboardViewFrameObserverKey; 17 | 18 | /// Observer for view's frame/bounds/center/transform 19 | @interface _YYKeyboardViewFrameObserver : NSObject 20 | @property (nonatomic, copy) void (^notifyBlock)(UIView *keyboard); 21 | - (void)addToKeyboardView:(UIView *)keyboardView; 22 | + (instancetype)observerForView:(UIView *)keyboardView; 23 | @end 24 | 25 | 26 | @implementation _YYKeyboardViewFrameObserver { 27 | __unsafe_unretained UIView *_keyboardView; 28 | } 29 | - (void)addToKeyboardView:(UIView *)keyboardView { 30 | if (_keyboardView == keyboardView) return; 31 | if (_keyboardView) { 32 | [self removeFrameObserver]; 33 | objc_setAssociatedObject(_keyboardView, &_YYKeyboardViewFrameObserverKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 34 | } 35 | _keyboardView = keyboardView; 36 | if (keyboardView) { 37 | [self addFrameObserver]; 38 | } 39 | objc_setAssociatedObject(keyboardView, &_YYKeyboardViewFrameObserverKey, self, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 40 | } 41 | 42 | - (void)removeFrameObserver { 43 | [_keyboardView removeObserver:self forKeyPath:@"frame"]; 44 | [_keyboardView removeObserver:self forKeyPath:@"center"]; 45 | [_keyboardView removeObserver:self forKeyPath:@"bounds"]; 46 | [_keyboardView removeObserver:self forKeyPath:@"transform"]; 47 | _keyboardView = nil; 48 | } 49 | 50 | - (void)addFrameObserver { 51 | if (!_keyboardView) return; 52 | [_keyboardView addObserver:self forKeyPath:@"frame" options:kNilOptions context:NULL]; 53 | [_keyboardView addObserver:self forKeyPath:@"center" options:kNilOptions context:NULL]; 54 | [_keyboardView addObserver:self forKeyPath:@"bounds" options:kNilOptions context:NULL]; 55 | [_keyboardView addObserver:self forKeyPath:@"transform" options:kNilOptions context:NULL]; 56 | } 57 | 58 | - (void)dealloc { 59 | [self removeFrameObserver]; 60 | } 61 | 62 | + (instancetype)observerForView:(UIView *)keyboardView { 63 | if (!keyboardView) return nil; 64 | return objc_getAssociatedObject(keyboardView, &_YYKeyboardViewFrameObserverKey); 65 | } 66 | 67 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 68 | 69 | BOOL isPrior = [[change objectForKey:NSKeyValueChangeNotificationIsPriorKey] boolValue]; 70 | if (isPrior) return; 71 | 72 | NSKeyValueChange changeKind = [[change objectForKey:NSKeyValueChangeKindKey] integerValue]; 73 | if (changeKind != NSKeyValueChangeSetting) return; 74 | 75 | id newVal = [change objectForKey:NSKeyValueChangeNewKey]; 76 | if (newVal == [NSNull null]) newVal = nil; 77 | 78 | if (_notifyBlock) { 79 | _notifyBlock(_keyboardView); 80 | } 81 | } 82 | 83 | @end 84 | 85 | 86 | 87 | @implementation YYKeyboardManager { 88 | NSHashTable *_observers; 89 | 90 | CGRect _fromFrame; 91 | BOOL _fromVisible; 92 | UIInterfaceOrientation _fromOrientation; 93 | 94 | CGRect _notificationFromFrame; 95 | CGRect _notificationToFrame; 96 | NSTimeInterval _notificationDuration; 97 | UIViewAnimationCurve _notificationCurve; 98 | BOOL _hasNotification; 99 | 100 | CGRect _observedToFrame; 101 | BOOL _hasObservedChange; 102 | 103 | BOOL _lastIsNotification; 104 | } 105 | 106 | - (instancetype)init { 107 | @throw [NSException exceptionWithName:@"YYKeyboardManager init error" reason:@"Use 'defaultManager' to get instance." userInfo:nil]; 108 | return [super init]; 109 | } 110 | 111 | - (instancetype)_init { 112 | self = [super init]; 113 | _observers = [[NSHashTable alloc] initWithOptions:NSPointerFunctionsWeakMemory|NSPointerFunctionsObjectPointerPersonality capacity:0]; 114 | [[NSNotificationCenter defaultCenter] addObserver:self 115 | selector:@selector(_keyboardFrameWillChangeNotification:) 116 | name:UIKeyboardWillChangeFrameNotification 117 | object:nil]; 118 | // for iPad (iOS 9) 119 | if ([UIDevice currentDevice].systemVersion.floatValue >= 9) { 120 | [[NSNotificationCenter defaultCenter] addObserver:self 121 | selector:@selector(_keyboardFrameDidChangeNotification:) 122 | name:UIKeyboardDidChangeFrameNotification 123 | object:nil]; 124 | } 125 | return self; 126 | } 127 | 128 | - (void)_initFrameObserver { 129 | UIView *keyboardView = self.keyboardView; 130 | if (!keyboardView) return; 131 | __weak typeof(self) _self = self; 132 | _YYKeyboardViewFrameObserver *observer = [_YYKeyboardViewFrameObserver observerForView:keyboardView]; 133 | if (!observer) { 134 | observer = [_YYKeyboardViewFrameObserver new]; 135 | observer.notifyBlock = ^(UIView *keyboard) { 136 | [_self _keyboardFrameChanged:keyboard]; 137 | }; 138 | [observer addToKeyboardView:keyboardView]; 139 | } 140 | } 141 | 142 | - (void)dealloc { 143 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 144 | } 145 | 146 | + (instancetype)defaultManager { 147 | static YYKeyboardManager *mgr; 148 | static dispatch_once_t onceToken; 149 | dispatch_once(&onceToken, ^{ 150 | mgr = [[self alloc] _init]; 151 | }); 152 | return mgr; 153 | } 154 | 155 | + (void)load { 156 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 157 | [self defaultManager]; 158 | }); 159 | } 160 | 161 | - (void)addObserver:(id)observer { 162 | if (!observer) return; 163 | [_observers addObject:observer]; 164 | } 165 | 166 | - (void)removeObserver:(id)observer { 167 | if (!observer) return; 168 | [_observers removeObject:observer]; 169 | } 170 | 171 | - (UIWindow *)keyboardWindow { 172 | UIWindow *window = nil; 173 | for (window in [UIApplication sharedApplication].windows) { 174 | if ([self _getKeyboardViewFromWindow:window]) return window; 175 | } 176 | window = [UIApplication sharedApplication].keyWindow; 177 | if ([self _getKeyboardViewFromWindow:window]) return window; 178 | 179 | NSMutableArray *kbWindows = nil; 180 | for (window in [UIApplication sharedApplication].windows) { 181 | NSString *windowName = NSStringFromClass(window.class); 182 | if ([self _systemVersion] < 9) { 183 | // UITextEffectsWindow 184 | if (windowName.length == 19 && 185 | [windowName hasPrefix:@"UI"] && 186 | [windowName hasSuffix:@"TextEffectsWindow"]) { 187 | if (!kbWindows) kbWindows = [NSMutableArray new]; 188 | [kbWindows addObject:window]; 189 | } 190 | } else { 191 | // UIRemoteKeyboardWindow 192 | if (windowName.length == 22 && 193 | [windowName hasPrefix:@"UI"] && 194 | [windowName hasSuffix:@"RemoteKeyboardWindow"]) { 195 | if (!kbWindows) kbWindows = [NSMutableArray new]; 196 | [kbWindows addObject:window]; 197 | } 198 | } 199 | } 200 | 201 | if (kbWindows.count == 1) { 202 | return kbWindows.firstObject; 203 | } 204 | 205 | return nil; 206 | } 207 | 208 | - (UIView *)keyboardView { 209 | UIWindow *window = nil; 210 | UIView *view = nil; 211 | for (window in [UIApplication sharedApplication].windows) { 212 | view = [self _getKeyboardViewFromWindow:window]; 213 | if (view) return view; 214 | } 215 | window = [UIApplication sharedApplication].keyWindow; 216 | view = [self _getKeyboardViewFromWindow:window]; 217 | if (view) return view; 218 | return nil; 219 | } 220 | 221 | - (BOOL)isKeyboardVisible { 222 | UIWindow *window = self.keyboardWindow; 223 | if (!window) return NO; 224 | UIView *view = self.keyboardView; 225 | if (!view) return NO; 226 | CGRect rect = CGRectIntersection(window.bounds, view.frame); 227 | if (CGRectIsNull(rect)) return NO; 228 | if (CGRectIsInfinite(rect)) return NO; 229 | return rect.size.width > 0 && rect.size.height > 0; 230 | } 231 | 232 | - (CGRect)keyboardFrame { 233 | UIView *keyboard = [self keyboardView]; 234 | if (!keyboard) return CGRectNull; 235 | 236 | CGRect frame = CGRectNull; 237 | UIWindow *window = keyboard.window; 238 | if (window) { 239 | frame = [window convertRect:keyboard.frame toWindow:nil]; 240 | } else { 241 | frame = keyboard.frame; 242 | } 243 | return frame; 244 | } 245 | 246 | #pragma mark - private 247 | 248 | - (double)_systemVersion { 249 | static double v; 250 | static dispatch_once_t onceToken; 251 | dispatch_once(&onceToken, ^{ 252 | v = [UIDevice currentDevice].systemVersion.doubleValue; 253 | }); 254 | return v; 255 | } 256 | 257 | - (UIView *)_getKeyboardViewFromWindow:(UIWindow *)window { 258 | /* 259 | iOS 6/7: 260 | UITextEffectsWindow 261 | UIPeripheralHostView << keyboard 262 | 263 | iOS 8: 264 | UITextEffectsWindow 265 | UIInputSetContainerView 266 | UIInputSetHostView << keyboard 267 | 268 | iOS 9: 269 | UIRemoteKeyboardWindow 270 | UIInputSetContainerView 271 | UIInputSetHostView << keyboard 272 | */ 273 | if (!window) return nil; 274 | 275 | // Get the window 276 | NSString *windowName = NSStringFromClass(window.class); 277 | if ([self _systemVersion] < 9) { 278 | // UITextEffectsWindow 279 | if (windowName.length != 19) return nil; 280 | if (![windowName hasPrefix:@"UI"]) return nil; 281 | if (![windowName hasSuffix:@"TextEffectsWindow"]) return nil; 282 | } else { 283 | // UIRemoteKeyboardWindow 284 | if (windowName.length != 22) return nil; 285 | if (![windowName hasPrefix:@"UI"]) return nil; 286 | if (![windowName hasSuffix:@"RemoteKeyboardWindow"]) return nil; 287 | } 288 | 289 | // Get the view 290 | if ([self _systemVersion] < 8) { 291 | // UIPeripheralHostView 292 | for (UIView *view in window.subviews) { 293 | NSString *viewName = NSStringFromClass(view.class); 294 | if (viewName.length != 20) continue; 295 | if (![viewName hasPrefix:@"UI"]) continue; 296 | if (![viewName hasSuffix:@"PeripheralHostView"]) continue; 297 | return view; 298 | } 299 | } else { 300 | // UIInputSetContainerView 301 | for (UIView *view in window.subviews) { 302 | NSString *viewName = NSStringFromClass(view.class); 303 | if (viewName.length != 23) continue; 304 | if (![viewName hasPrefix:@"UI"]) continue; 305 | if (![viewName hasSuffix:@"InputSetContainerView"]) continue; 306 | // UIInputSetHostView 307 | for (UIView *subView in view.subviews) { 308 | NSString *subViewName = NSStringFromClass(subView.class); 309 | if (subViewName.length != 18) continue; 310 | if (![subViewName hasPrefix:@"UI"]) continue; 311 | if (![subViewName hasSuffix:@"InputSetHostView"]) continue; 312 | return subView; 313 | } 314 | } 315 | } 316 | 317 | return nil; 318 | } 319 | 320 | - (void)_keyboardFrameWillChangeNotification:(NSNotification *)notif { 321 | if (![notif.name isEqualToString:UIKeyboardWillChangeFrameNotification]) return; 322 | NSDictionary *info = notif.userInfo; 323 | if (!info) return; 324 | 325 | [self _initFrameObserver]; 326 | 327 | NSValue *beforeValue = info[UIKeyboardFrameBeginUserInfoKey]; 328 | NSValue *afterValue = info[UIKeyboardFrameEndUserInfoKey]; 329 | NSNumber *curveNumber = info[UIKeyboardAnimationCurveUserInfoKey]; 330 | NSNumber *durationNumber = info[UIKeyboardAnimationDurationUserInfoKey]; 331 | 332 | CGRect before = beforeValue.CGRectValue; 333 | CGRect after = afterValue.CGRectValue; 334 | UIViewAnimationCurve curve = curveNumber.integerValue; 335 | NSTimeInterval duration = durationNumber.doubleValue; 336 | 337 | // ignore zero end frame 338 | if (after.size.width <= 0 && after.size.height <= 0) return; 339 | 340 | _notificationFromFrame = before; 341 | _notificationToFrame = after; 342 | _notificationCurve = curve; 343 | _notificationDuration = duration; 344 | _hasNotification = YES; 345 | _lastIsNotification = YES; 346 | 347 | [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_notifyAllObservers) object:nil]; 348 | if (duration == 0) { 349 | [self performSelector:@selector(_notifyAllObservers) withObject:nil afterDelay:0 inModes:@[NSRunLoopCommonModes]]; 350 | } else { 351 | [self _notifyAllObservers]; 352 | } 353 | } 354 | 355 | - (void)_keyboardFrameDidChangeNotification:(NSNotification *)notif { 356 | if (![notif.name isEqualToString:UIKeyboardDidChangeFrameNotification]) return; 357 | NSDictionary *info = notif.userInfo; 358 | if (!info) return; 359 | 360 | [self _initFrameObserver]; 361 | 362 | NSValue *afterValue = info[UIKeyboardFrameEndUserInfoKey]; 363 | CGRect after = afterValue.CGRectValue; 364 | 365 | // ignore zero end frame 366 | if (after.size.width <= 0 && after.size.height <= 0) return; 367 | 368 | _notificationToFrame = after; 369 | _notificationCurve = UIViewAnimationCurveEaseInOut; 370 | _notificationDuration = 0; 371 | _hasNotification = YES; 372 | _lastIsNotification = YES; 373 | 374 | [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_notifyAllObservers) object:nil]; 375 | [self performSelector:@selector(_notifyAllObservers) withObject:nil afterDelay:0 inModes:@[NSRunLoopCommonModes]]; 376 | } 377 | 378 | - (void)_keyboardFrameChanged:(UIView *)keyboard { 379 | if (keyboard != self.keyboardView) return; 380 | 381 | UIWindow *window = keyboard.window; 382 | if (window) { 383 | _observedToFrame = [window convertRect:keyboard.frame toWindow:nil]; 384 | } else { 385 | _observedToFrame = keyboard.frame; 386 | } 387 | _hasObservedChange = YES; 388 | _lastIsNotification = NO; 389 | 390 | [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_notifyAllObservers) object:nil]; 391 | [self performSelector:@selector(_notifyAllObservers) withObject:nil afterDelay:0 inModes:@[NSRunLoopCommonModes]]; 392 | } 393 | 394 | - (void)_notifyAllObservers { 395 | UIView *keyboard = self.keyboardView; 396 | UIWindow *window = keyboard.window; 397 | if (!window) { 398 | window = [UIApplication sharedApplication].keyWindow; 399 | } 400 | if (!window) { 401 | window = [UIApplication sharedApplication].windows.firstObject; 402 | } 403 | 404 | YYKeyboardTransition trans = {0}; 405 | 406 | // from 407 | if (_fromFrame.size.width == 0 && _fromFrame.size.height == 0) { // first notify 408 | _fromFrame.size.width = window.bounds.size.width; 409 | _fromFrame.size.height = trans.toFrame.size.height; 410 | _fromFrame.origin.x = trans.toFrame.origin.x; 411 | _fromFrame.origin.y = window.bounds.size.height; 412 | } 413 | trans.fromFrame = _fromFrame; 414 | trans.fromVisible = _fromVisible; 415 | 416 | // to 417 | if (_lastIsNotification || (_hasObservedChange && CGRectEqualToRect(_observedToFrame, _notificationToFrame))) { 418 | trans.toFrame = _notificationToFrame; 419 | trans.animationDuration = _notificationDuration; 420 | trans.animationCurve = _notificationCurve; 421 | trans.animationOption = _notificationCurve << 16; 422 | 423 | // Fix iPad(iOS7) keyboard frame error after rotate device when the keyboard is not docked to bottom. 424 | if (((int)[self _systemVersion]) == 7) { 425 | UIInterfaceOrientation ori = [UIApplication sharedApplication].statusBarOrientation; 426 | if (_fromOrientation != UIInterfaceOrientationUnknown && _fromOrientation != ori) { 427 | switch (ori) { 428 | case UIInterfaceOrientationPortrait: { 429 | if (CGRectGetMaxY(trans.toFrame) != window.frame.size.height) { 430 | trans.toFrame.origin.y -= trans.toFrame.size.height; 431 | } 432 | } break; 433 | case UIInterfaceOrientationPortraitUpsideDown: { 434 | if (CGRectGetMinY(trans.toFrame) != 0) { 435 | trans.toFrame.origin.y += trans.toFrame.size.height; 436 | } 437 | } break; 438 | case UIInterfaceOrientationLandscapeLeft: { 439 | if (CGRectGetMaxX(trans.toFrame) != window.frame.size.width) { 440 | trans.toFrame.origin.x -= trans.toFrame.size.width; 441 | } 442 | } break; 443 | case UIInterfaceOrientationLandscapeRight: { 444 | if (CGRectGetMinX(trans.toFrame) != 0) { 445 | trans.toFrame.origin.x += trans.toFrame.size.width; 446 | } 447 | } break; 448 | default: break; 449 | } 450 | } 451 | } 452 | } else { 453 | trans.toFrame = _observedToFrame; 454 | } 455 | 456 | if (window && trans.toFrame.size.width > 0 && trans.toFrame.size.height > 0) { 457 | CGRect rect = CGRectIntersection(window.bounds, trans.toFrame); 458 | if (!CGRectIsNull(rect) && !CGRectIsEmpty(rect)) { 459 | trans.toVisible = YES; 460 | } 461 | } 462 | 463 | if (!CGRectEqualToRect(trans.toFrame, _fromFrame)) { 464 | for (id observer in _observers.copy) { 465 | if ([observer respondsToSelector:@selector(keyboardChangedWithTransition:)]) { 466 | [observer keyboardChangedWithTransition:trans]; 467 | } 468 | } 469 | } 470 | 471 | _hasNotification = NO; 472 | _hasObservedChange = NO; 473 | _fromFrame = trans.toFrame; 474 | _fromVisible = trans.toVisible; 475 | _fromOrientation = [UIApplication sharedApplication].statusBarOrientation; 476 | } 477 | 478 | - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view { 479 | if (CGRectIsNull(rect)) return rect; 480 | if (CGRectIsInfinite(rect)) return rect; 481 | 482 | UIWindow *mainWindow = [UIApplication sharedApplication].keyWindow; 483 | if (!mainWindow) mainWindow = [UIApplication sharedApplication].windows.firstObject; 484 | if (!mainWindow) { // no window ?! 485 | if (view) { 486 | [view convertRect:rect fromView:nil]; 487 | } else { 488 | return rect; 489 | } 490 | } 491 | 492 | rect = [mainWindow convertRect:rect fromWindow:nil]; 493 | if (!view) return [mainWindow convertRect:rect toWindow:nil]; 494 | if (view == mainWindow) return rect; 495 | 496 | UIWindow *toWindow = [view isKindOfClass:[UIWindow class]] ? (id)view : view.window; 497 | if (!mainWindow || !toWindow) return [mainWindow convertRect:rect toView:view]; 498 | if (mainWindow == toWindow) return [mainWindow convertRect:rect toView:view]; 499 | 500 | // in different window 501 | rect = [mainWindow convertRect:rect toView:mainWindow]; 502 | rect = [toWindow convertRect:rect fromWindow:mainWindow]; 503 | rect = [view convertRect:rect fromView:toWindow]; 504 | return rect; 505 | } 506 | 507 | @end 508 | --------------------------------------------------------------------------------