- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当调用键盘时,我使用 UIKeyboardWillShowNotification 上下 ScrollView 。这在大多数情况下都可以正常工作。但是,键盘有一个完成按钮,可以生成 UIAlert。没有 UIAlert 没有问题,但是如果调用 UIAlert , ScrollView 会发生一些奇怪的事情,它似乎会停止工作,因为它的大小变得更小。
这是我正在使用的代码:
func adjustInsetForKeyboardShow(show: Bool, notification: NSNotification) {
guard let value = notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue else { return }
let keyboardFrame = value.CGRectValue()
let adjustmentHeight = (CGRectGetHeight(keyboardFrame) + 70) * (show ? 1 : -1)
scrollView.contentInset.bottom += adjustmentHeight
//scrollView.scrollIndicatorInsets.bottom += adjustmentHeight
}
func keyboardWillShow(notification: NSNotification) {
if keyboardVisible == false {
adjustInsetForKeyboardShow(true, notification: notification)
keyboardVisible = true
}
}
func keyboardWillHide(notification: NSNotification) {
adjustInsetForKeyboardShow(false, notification: notification)
keyboardVisible = false
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
键盘上有一个按钮,其中包含以下代码:
func displayAlert(title:String, message:String, view:UIViewController){
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { (action) -> Void in
}))
view.presentViewController(alert, animated: true, completion: nil)
}
结果是发出警报,然后当我按下“确定”按钮时, ScrollView 会中断。
有人可以帮忙吗?如果您需要更多代码,请告诉我
最佳答案
如果可能的话,我首先建议您使用表格 View 而不是 ScrollView 。其次,我不知道您是否测试过,但这些通知被多次调用,并且有时它们的行为与您的预期不同。我还没有尝试过,但我假设一旦您显示 UIAlert,这些方法之一就会被触发,然后您的内容大小就会变得疯狂。尝试设置断点,看看会发生什么。另外,尝试在返回时关闭键盘,然后调用 displayAlert()。另外,根据经验,当您离开屏幕时,删除观察者的 deinit 方法不会被调用,我不知道您是否有使用它的理由?最好使用 viewWillAppear、viewWillDissapear 方法。
关于ios - KeyboardWillShowNotification 和 UIAlert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37421860/
我有一个 UIKeyboardWillShowNotification 和 UIKeyboardWillHideNotification 的观察者。 [[NSNotificationCenter de
我正在使用 keyboardWasShown 和 keyboardWillBeHidden 通知来滑动 View 以获取可见的 TextView 。 我有一个带有六个选项卡的 UITabBar 应用程
这是操作顺序的问题 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self
我有一个带有文本字段的自定义 UITableViewCell。单元格的文本字段设置为调用委托(delegate)函数。里面 -(BOOL)textFieldShouldReturn:(UIText
我已订阅 keyboardWillShowNotification 和 keyboardWillHideNotification 以在我的 UI 中移动。我注意到,当我通过点击“Go”按钮关闭键盘时,
我需要在键盘可见后立即向上移动 UIView。但我现在面临的问题是,当我使用自定义键盘(例如 SwiftKey)时,我的 UIKeyboardWillShowNotification 被调用了三次,这
这个问题在这里已经有了答案: can't get correct value of keyboard height in iOS8 (10 个答案) 关闭 8 年前。 我的 UI 在显示键盘时需要进
我正在 viewdidload 上创建通知UIKeyboardWillShowNotification 并在 上删除它 View 将消失 . 当键盘出现在屏幕上并按预期调用一次通知时,我锁定了屏幕。通
我不知道出了什么问题。我的导航栏中有 2 个右侧按钮,当键盘打开时,我需要 A 和 B 按钮,当键盘关闭时,我需要 A 和 C,或者可能只是 C。我这样做了。我使用 UIKeyboardWillSho
当调用键盘时,我使用 UIKeyboardWillShowNotification 上下 ScrollView 。这在大多数情况下都可以正常工作。但是,键盘有一个完成按钮,可以生成 UIAlert。没
我有一个带有“安全文本输入”的表单,我想在键盘打开时向上滚动我的 View 。 我正在收听 UIKeyboardWillShowNotification 但是当焦点位于密码字段时,会再次发送此通知并且
我会在键盘出现和消失时创建通知。 override func viewDidLoad() { super.viewDidLoad() // Creates notification w
我想在不使用可用的键盘通知的情况下获取键盘的大小。原因是我在 View 上有多个文本字段,我不需要为它们的所有 调整 View 的大小,正如我在几乎每个示例中看到的那样。我只需要调整一些文本字段/ V
我有一个非常奇怪的问题,当我按回车键时会发生这种情况,并且只有当我第一次按回车键时才会发生这种情况,每次下一次它都会按预期工作。 我有一个简单的类来管理键盘,它接受我拒绝委托(delegate)给我的
我正在使用日期选择器作为文本字段的输入 View 。在 View 中将出现我已添加 UIKeyboardWillShowNotification。 我的问题是,当要查看日期选择器时,它也会出现 Key
我正在使用 UIKeyboardWillShowNotification 来检测用户何时选择文本字段以及何时打开键盘。在 ios 8 和旧版本的 iOS 中它工作正常但今天我升级到 iOS 9 和 x
初始化部分: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)
我正在使用 UIKeyboardWillShowNotification 和 UIKeyboardWillHideNotification 处理键盘框架更改。当用户通过按下“globe”键打开、隐藏键
我在 IOS 7 和 IOS 8 设备上运行相同的代码但结果不同 给定一个包含两个文本字段的屏幕 在 IOS 7 中,如果我触摸第一个字段 keyboardWillShow 会被调用,但如果我在键盘已
在我标题为handleKeyboardWillShow的函数上,我的输入文本字段的移动速度高于预期。我的目的是将文本字段固定到键盘 View 的顶部。我还将代码添加到了似乎导致问题的文本字段的创建中。
我是一名优秀的程序员,十分优秀!