微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – 调整inputAccessoryView中的文本字段大小

我一直试图让UITextView整周调整大小.我不知道应该怎么做,所以我决定包括几乎所有相关的代码.

我有这个对话视图:

这个对话视图是一个内部有UITableView的UIViewController(使用约束).我有一个自定义UIView子类ConversationToolbar设置为inputAccessoryView(包含它的UIViewController可以成为第一个响应者,因此视图始终可见),其中包含2个子视图.一个用于UITextView和左右按钮,一个用于表情符号.表情符号仅在点按左键时显示

当选择一个时,它会显示在浮动标签中:

当使用多行时,我现在无法调整此UITextView的大小.我曾尝试自己计算所有帧,但那时似乎与我的约束以某种奇怪的方式发生冲突.几乎总是UITextView太小或仅在我按另一个键来更新视图后调整大小.或者UITextView在键盘上变大,或者在键盘解除时滑出视图.

我已从我的代码删除了所有调整大小的功能,我想知道我需要做什么才能调整大小.

在我的ConversationViewController中:

var toolbar: ConversationToolbar!

override var inputAccessoryView: UIView! {
    get {
        if toolbar == nil {
            toolbar = NSBundle.mainBundle().loadNibNamed("ConversationToolbar",owner: nil,options: nil).last! as ConversationToolbar
            toolbar.frame.size = CGSize(width: UIScreen.mainScreen().bounds.size.width,height: 80)
            toolbar.delegate = self
            toolbar.setDraft(conversation.draft)
        }
        return toolbar
    }
}

使用ConversationToolbar.xib是:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsversion="6254" systemVersion="14D87p" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
    </dependencies>
    <objects>
        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
        <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
        <view contentMode="scaletoFill" id="iN0-l3-epB" customClass="ConversationToolbar" customModule="Heaven_Help" customModuleProvider="target">
            <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
            <subviews>
                <view contentMode="scaletoFill" translatesAutoresizingMaskIntoConstraints="NO" id="s5O-PN-dtz">
                    <rect key="frame" x="0.0" y="554" width="600" height="46"/>
                    <subviews>
                        <button opaque="NO" contentMode="scaletoFill" horizontalCompressionResistancePriority="749" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="pbw-hg-sNn">
                            <rect key="frame" x="0.0" y="0.0" width="36" height="46"/>
                            <inset key="contentEdgeInsets" minX="8" minY="0.0" maxX="8" maxY="0.0"/>
                            <state key="normal" title="
                
                                

原文地址:https://www.jb51.cc/iOS/334136.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐