- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有一个 scrollView,我想在显示键盘时向上滚动。
当键盘显示时,我因此错误而崩溃:
2014-09-29 14:48:50.738 swrd[1563:472888] -[swrd.EditPhotoViewController keyboardWasShown]:无法识别的选择器发送到实例 0x14ed36640
这是我的代码,有什么问题吗?:
func registerForKeyboardNotifications ()-> Void {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWasShown", name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillBeHidden", name: UIKeyboardWillHideNotification, object: nil)
}
func deregisterFromKeyboardNotifications () -> Void {
let center: NSNotificationCenter = NSNotificationCenter.defaultCenter()
center.removeObserver(self, name: UIKeyboardDidHideNotification, object: nil)
center.removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
}
func keyboardWasShown (notification: NSNotification) {
let info : NSDictionary = notification.userInfo!
let keyboardSize = info.objectForKey(UIKeyboardFrameBeginUserInfoKey)?.frame
let insets: UIEdgeInsets = UIEdgeInsetsMake(self.scrollView.contentInset.top, 0, keyboardSize!.height, 0)
self.scrollView.contentInset = insets
self.scrollView.scrollIndicatorInsets = insets
self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, self.scrollView.contentOffset.y + keyboardSize!.height)
}
func keyboardWillBeHidden (notification: NSNotification) {
let info : NSDictionary = notification.userInfo!
let keyboardSize = info.objectForKey(UIKeyboardFrameBeginUserInfoKey)?.frame
let insets: UIEdgeInsets = UIEdgeInsetsMake(self.scrollView.contentInset.top, 0, keyboardSize!.height, 0)
self.scrollView.contentInset = insets
self.scrollView.scrollIndicatorInsets = insets
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
self.registerForKeyboardNotifications()
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(true)
self.deregisterFromKeyboardNotifications()
}
最佳答案
在您的代码中,keyboardWasShown
和 keyboardWasHidden
各有一个参数,NSNotification
。您需要用冒号终止 addObserver
中的选择器,以便它通过。即,keyboardWasShown
和 keyboardWasShown:
是不同的选择器。
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWasShown:", name: UIKeyboardDidShowNotification, object: nil)
关于ios - swift : scroll the view up when keyboard shows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26100545/
当我的 android sdk 更新到最新版本时,我遇到的问题是:我无法使用计算机键盘在 Android Emulator 中输入文本,并且我无法使用 Android Emulator 键盘(屏幕旁边
我一直在尝试 APL。我正在运行 Windows 10 并且我已经安装了 Dyalog 18.0,以及 VS Code 的 APL 语言和 APL 反引号符号扩展。 但是即使我没有运行任何这些程序,有
我正在构建我的键盘扩展应用程序,当用户点击它时,我在按钮上添加了按键弹出动画。它适用于内部图像,但对于顶行图像弹出区域在剪辑 subview 时变得隐藏。我尝试使用 ClipToBound 属性并将其
我使用 MSKLC 制作了自定义键盘布局。 我以为我仔细按照说明操作了chose appropriate values对于LOCALENAME和 LOCALID参数。 但是,在通过按 Win+Spac
我一直在尝试弄清楚如何使用 Scanner 类一次输入多个标记。我找到了一些可以完美运行的代码。我知道 Scanner.hasNext 方法可以无限期地阻塞。为什么此代码中的行 keyboard =
我应该为 90% 仅使用键盘的网络应用程序使用什么技术? 我想要一个大部分时间只使用键盘的网络应用程序。哪种技术可以为我提供这种便利? 我不在乎是 java 框架还是基于 .net 或其他的东西。:)
对于文字游戏,我想在 Swift 中以编程方式创建一个 UITextField,它只允许用户输入和删除大写字母(没有空格键、回车键、大写字母等)。像这样: Desired Keyboard Layou
我在合成器上工作,我希望显示一个键盘/钢琴,用户可以在合成器的任何 Activity 中打开或关闭以弹奏琴键。最好的解决方案是它的行为是否像普通的软键盘一样,这意味着,我希望“虚拟钢琴”将当前 Act
作为haskell 的绝对初学者,我一直在阅读有关haskell 的各种文章、pdf 和教程。大多数示例/示例代码都包含数学字符。即使是打字的常见任务 -> 我必须输入: - & > 事实是我不知道如
对于自动化测试应用程序,我必须模拟大量 unicode 键盘输入到旧的 X11 应用程序(我没有任何源代码访问权限)。我的程序通过标准输入从 UCS-2 LE 编码的输入流中获取输入,基本操作如下:
问题 点击 uitextfield 时会显示键盘。一旦键盘出现,它就可以正常工作。我可以将键盘更改为除表情符号键盘之外的任何键盘。每次尝试切换到表情符号键盘时,它都会崩溃。 这是崩溃日志 2019-0
I want to record mouse and keyboard simultaneously and replay them later. When MIDDLE MOUSE is pr
第 1 步:向用户发送消息 ReplyKeyboardMarkup带有几个按钮(例如 ["Yes", "No"] ) 第 2 步:如果用户单击其中一个按钮(例如“Yes" ),我想用内嵌键盘显示一条消
在我们现在正在编写的应用程序中,我们遇到了一个问题,即如果将焦点放在底部工作表中的文本字段,键盘会在短暂的闪烁后消失。 在尝试修复它数小时后,我试图隔离这种奇怪的行为并提出了以下错误: 如果我在不是主
我正在开发一个带有EXPO管理工作流的反应原生应用程序。。我在应用程序中有一个TextInput域,我希望它通过蓝牙接受来自物理条形码扫描器的输入。。问题:当通过蓝牙连接条形码扫描仪时,移动设备将其标
我正在寻找一种将我的 Raspberry Pi Zero 用作 HID 鼠标的方法。 目标:我将 Pi 放入我的电脑,它会自动开始从上到下和从下到上快速移动鼠标。 所以原则上像 USB Rubber
我有一台华硕笔记本电脑 (F50SF),我在 C++ 中尝试拦截多媒体键(下一首轨道、上一首轨道、播放/暂停等),但我无法弄清楚如何做到这一点。我试过 GetAsyncKeyState(VK_MEDI
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 1年前关闭。 Improve this qu
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
在我的代码中,我似乎无法让键盘默认为黑色。我已经尝试了其他帖子中的解决方案,但没有成功。不确定我是否遗漏了什么。我希望它适用于所有 View Controller ,所以我想把它放在我的应用程序委托(
我是一名优秀的程序员,十分优秀!