ios9 - Xcode 7 - Swift - 键盘在模拟器中正确显示但在实际设备上不正确

标签 ios iphone xcode swift

我遇到了一个不寻常的问题,即键盘正确响应模拟器中的输入焦点操作(禁用硬键盘),但是当我在实际设备上构建和测试时,键盘没有出现。

该应用程序是一个简单的 SFSafariViewController。我是否需要在 Info.plist 或类似的东西中指定键盘设置?

-----更新-----

添加源代码:

import UIKit
import SafariServices

class ViewController: UIViewController
{
    private var urlString:String = "https://example.com"

    override func viewDidLoad()
    {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func viewDidAppear(animated: Bool) {

        super.viewDidAppear(animated)

        // This will remove the status (battery, time, etc) bar
        UIApplication.sharedApplication().statusBarHidden = true

        let svc = SFSafariViewController(URL: NSURL(string: self.urlString)!)

        // Kind of a hack, in that we really aren't removing the navbar
        //  Rather we are adjusting the starting point of the vpc object so it appears as the navbar is hidden
        self.presentViewController(svc, animated: true) {

            var frame = svc.view.frame
            let OffsetY: CGFloat = 42

            frame.origin = CGPoint(x: frame.origin.x, y: frame.origin.y - OffsetY)
            frame.size = CGSize(width: frame.width, height: frame.height + OffsetY)
            svc.view.frame = frame
        }
    }

    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

最佳答案

呃。作为 ios 开发的新手,我 100% 确定我的代码很糟糕,这导致键盘不出现。因此,今天早上我创建了一个测试项目,并将项目中的每一行代码添加到测试项目中,以查看是哪个代码导致了感知到的损坏。

所有代码加回来后,我重新编译了一遍测试工程,果然成功了。与普通项目完全相同的代码,wtf?所以后来我意识到一定有一些缓存异常导致了这个问题,果然我找到了这个 post关于如何清除 Xcode 缓存。清除缓存后,我重新加载我的项目,重新编译,果然,我的项目按预期运行。

简而言之,如有疑问,请清除缓存。

关于ios9 - Xcode 7 - Swift - 键盘在模拟器中正确显示但在实际设备上不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33877085/

相关文章:

ios - 如何从 NSDictionary 中删除作为 NSDictionary 元素的条目?

iphone - 有没有办法在按下 UIButton 时获取用户触摸的位置?

xcode - 使用 XCode 8 如何定位我的应用程序以在 macOS 上运行(它已经在 iPhone/iPad 上运行)?

swift - Eureka- 根据 ActionSheetRow 值隐藏行

ios - 检查时间是在两次保存的文本字符串时间之前还是之后

ios - 缩放 UITextView 并保持文本清晰度

ios - 搜索字符串,但允许不同但相似的标点字符

iOS 后台蓝牙事件

iphone - 从多个 UIButtons 调用一个选择器

iphone - 网站导致移动Safari崩溃(可复制)