最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift实现点击文本输入框时显示键盘后页面自动上移

iOS crifan 3326浏览 0评论

知道有:

michaeltyson/TPKeyboardAvoiding: A drop-in universal solution for moving text fields out of the way of the keyboard in iOS

hackiftekhar/IQKeyboardManager: Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more.

对于已有一个项目中:

先去试试使用:

https://github.com/hackiftekhar/IQKeyboardManager

github “hackiftekhar/IQKeyboardManager”

试试:

licrifandeMacBook-Pro:Workhub crifan$ carthage update IQKeyboardManager –platform iOS
*** Cloning IQKeyboardManager

结果出错:

licrifandeMacBook-Pro:Workhub crifan$ carthage update IQKeyboardManager –platform iOS
*** Cloning IQKeyboardManager
*** Fetching SwiftHTTPStatusCodes
*** Fetching PageMenu
*** Fetching Kingfisher
*** Fetching SwiftyJSON
*** Fetching SwiftHEXColors
*** Fetching SwiftKeychainWrapper
*** Fetching Alamofire
*** Fetching XCGLogger
*** Fetching realm-cocoa
*** Fetching Cartography
*** Checking out IQKeyboardManager at “v4.0.4”
*** xcodebuild output can be found in /var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/carthage-xcodebuild.FaOqCW.log
*** Building scheme “IQKeyboardManagerSwift” in IQKeyboardManager.xcodeproj
*** Building scheme “IQKeyboardManager” in IQKeyboardManager.xcodeproj
Failed to read file or folder at /Users/crifan/Library/Developer/Xcode/DerivedData/IQKeyboardManager-chnohoqoqmxkcwhebmkelfdqjckr/Build/Products/Release-iphoneos/IQKeyboardManager.framework

但是此处的Carthage下面是存在的:

IQKeyboardManagerSwift.framework

和:

IQKeyboardManager.framework

然后去导入:

IQKeyboardManagerSwift.framework

试试

去尝试使用:

import IQKeyboardManagerSwift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDelegate {
    var window: UIWindow?
    func application(application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
        IQKeyboardManager.sharedManager().enable = true
        return true
    }

然后两次运行都报错。

然后clean后,多次尝试后运行,终于可以了:

但是很明显,多处一个Done

-》要想办法把Done去掉:

通过查看描述文档,好像是:

IQKeyboardManager的enableAutoToolbar

IQKeyboardManager.sharedManager().enableAutoToolbar = false

果然就没了:

但是还有个问题:键盘上移期间,会出现一个黑色边框:

然后试了很多参数,都不行:

        IQKeyboardManager.sharedManager().keyboardDistanceFromTextField = 20
//        IQKeyboardManager.sharedManager().shouldToolbarUsesTextFieldTintColor = true

swift keyboard moving up show black background

swift keyboard moving up show black

ios keyboard moving up show black

转载请注明:在路上 » [已解决]swift实现点击文本输入框时显示键盘后页面自动上移

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.188 seconds, using 22.05MB memory