- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我的 inputAccessoryView
出现了一个奇怪的错误。在转换过程中,它看起来像这样:
转换后,它应该显示为:
我像这样覆盖属性:
override var inputAccessoryView: UIView! {
get {
if composeView == nil {
composeView = CommentComposeView(frame: CGRectMake(0, 0, 0, MinimumToolbarHeight - 0.5))
self.setupSignals()
}
return composeView
}
}
我想知道是否有人可以指出我正在做的事情中的任何明显缺陷,或者提供一些更多信息来说明如何确保我的 View 在转换之前、期间和之后按应有的方式显示。
谢谢!
编辑
这是我的 CommentComposeView
:
import UIKit
class CommentComposeView: UIToolbar {
var textView: SAMTextView!
var sendButton: UIButton!
private var didSetConstraints: Bool = false
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.initialize()
}
override init(frame: CGRect) {
super.init(frame: frame)
self.initialize()
}
private func initialize() {
textView = SAMTextView(frame: CGRectZero)
sendButton = UIButton.buttonWithType(.System) as UIButton
self.barStyle = .Black
self.translucent = true
textView.backgroundColor = UIColor.presentOffWhite()
textView.font = UIFont.presentLightMedium()
textView.layer.borderWidth = 0.5
textView.layer.cornerRadius = 5
textView.placeholder = "Comment"
textView.scrollsToTop = false
textView.textContainerInset = UIEdgeInsetsMake(4, 3, 3, 3)
textView.keyboardAppearance = .Dark
textView.keyboardType = .Twitter
self.addSubview(textView)
sendButton = UIButton.buttonWithType(.System) as UIButton
sendButton.enabled = false
sendButton.titleLabel!.font = UIFont.presentBoldLarge()
sendButton.setTitle("Send", forState: .Normal)
sendButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)
sendButton.setTitleColor(UIColor.presentCyan(), forState: .Highlighted)
sendButton.setTitleColor(UIColor.presentLightGray(), forState: .Disabled)
sendButton.contentEdgeInsets = UIEdgeInsetsMake(6, 6, 6, 6)
self.addSubview(sendButton)
RAC(self.sendButton, "enabled") <~ self.textView.rac_textSignal()
.map { text in
return (text as NSString).length > 0
}
textView.setTranslatesAutoresizingMaskIntoConstraints(false)
sendButton.setTranslatesAutoresizingMaskIntoConstraints(false)
}
override func updateConstraints() {
super.updateConstraints()
if !didSetConstraints {
// TODO: Replace raw constraints with a friendlier looking DSL
self.addConstraint(
NSLayoutConstraint(item: textView, attribute: .Left, relatedBy: .Equal, toItem: self, attribute: .Left, multiplier: 1, constant: 8)
)
self.addConstraint(
NSLayoutConstraint(item: textView, attribute: .Top, relatedBy: .Equal, toItem: self, attribute: .Top, multiplier: 1, constant: 7.5)
)
self.addConstraint(
NSLayoutConstraint(item: textView, attribute: .Right, relatedBy: .Equal, toItem: sendButton, attribute: .Left, multiplier: 1, constant: -2)
)
self.addConstraint(
NSLayoutConstraint(item: textView, attribute: .Bottom, relatedBy: .Equal, toItem: self, attribute: .Bottom, multiplier: 1, constant: -8)
)
self.addConstraint(
NSLayoutConstraint(item: sendButton, attribute: .Right, relatedBy: .Equal, toItem: self, attribute: .Right, multiplier: 1, constant: 0)
)
self.addConstraint(
NSLayoutConstraint(item: sendButton, attribute: .Bottom, relatedBy: .Equal, toItem: self, attribute: .Bottom, multiplier: 1, constant: -4.5)
)
}
}
}
最佳答案
这是 iOS8 的 inputAccessoryView 自动布局问题。问题是 UIToolbar 的类 _UIToolbarBackground
的 subview 在初始布局期间未正确定位。尝试做接下来的事情:
CommentComposeView
成为 UIView
的子类,而不是 UIToolbar
,添加 UIToolbar
的实例作为 subview 。CommentComposeView
CommentComposeView
中覆盖 -layoutSubviews
,如下所示:- (void)layoutSubviews
{
[super layoutSubviews];
contentToolbar.frame = self.bounds;
sendButton.frame = CGRectMake(0.f, 0.f, 44.f, self.bounds.size.height);
textView.frame = CGRectMake(44.f, 0.f, self.bounds.size.width - 44.f, self.bounds.size.height);
}
关于ios - Swift inputAccessoryView 覆盖错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25188392/
我正在尝试在 SwiftUI 中的 TextField 上实现一个 inputAccessoryView。目标是在键盘上方出现一个“完成”按钮,按下该按钮时会摆脱键盘(即 resignFirstRes
我已添加 InputAccessoryView到我的键盘消失。它炒得很好。但在某些 ViewController它没有出现。即使那个方法也不会调用。 我有一个按钮。当我点击我的文本字段时,它会自动成为
自从我升级到 Xcode 5.1 后,我的 inputAccessoryView 出现了问题。 如您在附图中所见,按键在 inputAccessoryView 内的工具栏后面弹出。我认为它与新版本的
我正在为 UITextField 和 UIToolbar 设置一个 datepicker 来代替键盘。我希望能够关闭 accessoryView,但它没有正常运行。虽然我按下了 Done 按钮,但没有
我有一个 Objective-C 项目,我想在其中添加一个 inputAccessoryView 到 UITextView 的子类。老办法是 self.myTextView.inputAccessor
我已经看过了this solution .我已经创建了一个显示错误的示例项目。 该 View 只有一个 UITextField。 这是我的代码: class ViewController: UIVie
Problem relates to this.我正在尝试使用我制作的自定义 View ,它有两个 TextField 输入和一个按钮,我使用 IB 它的 xib 制作它,我将它放在我的 Storyb
今天早上,我正在查看我在某个地方找到的一些旧代码(并在应用程序中使用),这些代码破解了 UIAlertView 以便从用户那里获取一串输入。出于这个目的,它有点矫枉过正,看起来很傻,但我从未见过更简单
我正在尝试复制 Facebook Messenger 应用程序,其中有一个 UITextView 附加到键盘顶部。 由于此应用的性质,我需要附加我的 View ,而不是在出现键盘时手动上下滚动Scro
是否可以在键盘上方创建 inputAccessoryView,用于拆分模式下的屏幕全宽?系统会自动调整其大小以适合应用程序框架。这是 iOS 中的错误吗? 最佳答案 您可以使用此方法检测您的键盘是否处
知道如何让 inputAccessoryView 锚定到标签栏而不是屏幕底部吗? 我创建了一个 UIViewController 并覆盖了以下方法: -(BOOL)canBecomeFirstResp
我正在尝试创建一个类似于 iOS 消息传递应用程序的消息传递界面。我正在努力解决的部分是覆盖 inputAccessoryView(在 View Controller 上)对我没有影响。 如果您查看下
我正在尝试添加带有“完成”按钮的 UIView 作为文本字段的输入附件 View 。 let view = UIView() let doneButton = UIBu
UISearchBar 似乎将 inputAccessoryView 作为 readOnly 属性。如何使用我自己的 customToolbar 进行设置? 最佳答案 编辑:如以下评论中所述,这不再是
我在 textView 的 inputAccessoryView 属性中使用工具栏。当键盘显示时,它会按预期显示工具栏。旋转设备时,我想删除工具栏。我试过: myTextView.inputAcce
我正在尝试实现与 Apple 消息应用中底部文本输入栏类似的定位行为。 我尝试了很多方法,到处搜索,有很多类似的问题,但没有一个是令人满意的。 要指定: 在 View 底部有一个UIToolbar 工
我已经为我的应用程序中的某些 UITextFields 添加了一个 inputAccessoryView 到 iOS 键盘。这个附件 View 为用户提供了基本功能(一些按钮在我的应用程序的其他地方没
我正在以模态方式呈现一个 UIViewController,该 View 包含各种 UITextFields。我已经重写了模态视图 InputAccessoryView,以便它显示一个简单的 View
全部, 我的 UITextView 上附加了一个可滚动的 InputAccessoryView。创建如下: 创建一个 UIScrollView 添加一个水平 UIStackView。 将堆栈 View
我有一个简单的 UIViewController,其中包含一些对象:一个 UITextView 和一个作为 InputAccessoryView 添加到 UTextView 的 UIToolBar。当
我是一名优秀的程序员,十分优秀!