Ios 我如何制作表情符号或键入任何东西

Ios 我如何制作表情符号或键入任何东西,ios,xcode,swift,ios8,xcode6,Ios,Xcode,Swift,Ios8,Xcode6,我目前正在使用自定义键盘 当我尝试在新窗口中组合textDocumentProxy时遇到了一个问题 所以有添加表情符号键盘按钮 我通过添加两个表情符号按钮来传递这个页面,现在我的问题是如何将textDocumentProxy合并到另一个窗口或它们之间的链接,甚至可以键入表情符号 我尝试键入任何内容,而不仅仅是表情符号 完整的源代码在这里 您需要根据需要在项目中更改许多内容,比如您可以通过隐藏tableView并在其上添加一个UIView来使用该设置视图,然后您可以将表情添加到该视图中,当用户从

我目前正在使用自定义键盘 当我尝试在新窗口中组合textDocumentProxy时遇到了一个问题

所以有添加表情符号键盘按钮 我通过添加两个表情符号按钮来传递这个页面,现在我的问题是如何将textDocumentProxy合并到另一个窗口或它们之间的链接,甚至可以键入表情符号

我尝试键入任何内容,而不仅仅是表情符号

完整的源代码在这里


您需要根据需要在项目中更改许多内容,比如您可以通过隐藏tableView并在其上添加一个UIView来使用该设置视图,然后您可以将表情添加到该视图中,当用户从键盘单击设置按钮时,您可以隐藏表情视图并显示tableView,但当用户想要键入您想要的微笑时不需要隐藏任何东西,只需显示您的表情视图即可


是您的更新项目。

所以您想从自定义键盘的设置视图中删除表情符号按钮吗?是的,请告诉我好吗?对不起,我可能无法很好地解释我自己,但我很高兴向您发送源代码,那么您如何更好地理解我?您确定当用户启用表情符号按钮时,您可以将更改存储到
NSUserDefaults
。我向您发送了一封感谢信
import UIKit

class DefaultSettings1: ExtraView, UITableViewDelegate {

    @IBOutlet var tableView1: UITableView?
    @IBOutlet var effectsView: UIVisualEffectView?
    @IBOutlet var backButton1: UIButton?
    @IBOutlet var settingsLabel: UILabel?
    @IBOutlet var pixelLine: UIView?
    @IBOutlet var keyPressed: UIButton?



    override var darkMode: Bool {
        didSet {
            self.updateAppearance(darkMode)
        }
    }

    let cellBackgroundColorDark = UIColor.whiteColor().colorWithAlphaComponent(CGFloat(0.25))
    let cellBackgroundColorLight = UIColor.whiteColor().colorWithAlphaComponent(CGFloat(1))
    let cellLabelColorDark = UIColor.whiteColor()
    let cellLabelColorLight = UIColor.blackColor()
    let cellLongLabelColorDark = UIColor.lightGrayColor()
    let cellLongLabelColorLight = UIColor.grayColor()

    // TODO: these probably don't belong here, and also need to be localized
      required init(globalColors: GlobalColors.Type?, darkMode: Bool, solidColorMode: Bool) {
        super.init(globalColors: globalColors, darkMode: darkMode, solidColorMode: solidColorMode)
        self.loadNib()
    }



    required init(coder aDecoder: NSCoder) {
        fatalError("loading from nib not supported")
    }

    func loadNib() {
        let assets = NSBundle(forClass: self.dynamicType).loadNibNamed("DefaultSettings1", owner: self, options: nil)

        if assets.count > 0 {
            if var rootView = assets.first as? UIView {
                rootView.setTranslatesAutoresizingMaskIntoConstraints(false)
                self.addSubview(rootView)

                let left = NSLayoutConstraint(item: rootView, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 0)
                let right = NSLayoutConstraint(item: rootView, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 0)
                let top = NSLayoutConstraint(item: rootView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0)
                let bottom = NSLayoutConstraint(item: rootView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0)

                self.addConstraint(left)
                self.addConstraint(right)
                self.addConstraint(top)
                self.addConstraint(bottom)
            }
        }

        self.tableView1?.registerClass(DefaultSettings1TableViewCell.self, forCellReuseIdentifier: "cell")
        self.tableView1?.estimatedRowHeight = 44;
        self.tableView1?.rowHeight = UITableViewAutomaticDimension;

        // XXX: this is here b/c a totally transparent background does not support scrolling in blank areas
        self.tableView1?.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.01)

        self.updateAppearance(self.darkMode)
    }



    func tableView1(tableView1: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        if var cell = tableView1.dequeueReusableCellWithIdentifier("cell") as? DefaultSettings1TableViewCell {

            if cell.sw.allTargets().count == 0 {
                cell.sw.addTarget(self, action: Selector("toggleSetting1:"), forControlEvents: UIControlEvents.ValueChanged)
            }



            cell.backgroundColor = (self.darkMode ? cellBackgroundColorDark : cellBackgroundColorLight)
            cell.label.textColor = (self.darkMode ? cellLabelColorDark : cellLabelColorLight)
            cell.longLabel.textColor = (self.darkMode ? cellLongLabelColorDark : cellLongLabelColorLight)

            cell.changeConstraints()

            return cell
        }
        else {
            assert(false, "this is a bad thing that just happened")
            return UITableViewCell()
        }
    }




    func updateAppearance(dark: Bool) {
        if dark {
            self.effectsView?.effect
            let blueColor = UIColor(red: 135/CGFloat(255), green: 206/CGFloat(255), blue: 250/CGFloat(255), alpha: 1)
            self.pixelLine?.backgroundColor = blueColor.colorWithAlphaComponent(CGFloat(0.5))
            self.backButton1?.setTitleColor(blueColor, forState: UIControlState.Normal)
            self.settingsLabel?.textColor = UIColor.whiteColor()

            if let visibleCells = self.tableView1?.visibleCells() {
                for cell in visibleCells {
                    if var cell = cell as? UITableViewCell {
                        cell.backgroundColor = cellBackgroundColorDark
                        var label = cell.viewWithTag(2) as? UILabel
                        label?.textColor = cellLabelColorDark
                        var longLabel = cell.viewWithTag(3) as? UITextView
                        longLabel?.textColor = cellLongLabelColorDark
                    }
                }
            }
        }
        else {
            let blueColor = UIColor(red: 0/CGFloat(255), green: 122/CGFloat(255), blue: 255/CGFloat(255), alpha: 1)
            self.pixelLine?.backgroundColor = blueColor.colorWithAlphaComponent(CGFloat(0.5))
            self.backButton1?.setTitleColor(blueColor, forState: UIControlState.Normal)
            self.settingsLabel?.textColor = UIColor.grayColor()

            if let visibleCells = self.tableView1?.visibleCells() {
                for cell in visibleCells {
                    if var cell = cell as? UITableViewCell {
                        cell.backgroundColor = cellBackgroundColorLight
                        var label = cell.viewWithTag(2) as? UILabel
                        label?.textColor = cellLabelColorLight
                        var longLabel = cell.viewWithTag(3) as? UITextView
                        longLabel?.textColor = cellLongLabelColorLight
                    }
                }
            }
        }
    }

    }

class DefaultSettings1TableViewCell: UITableViewCell {
       var sw: UISwitch
    var label: UILabel
    var longLabel: UITextView
    var constraintsSetForLongLabel: Bool
    var cellConstraints: [NSLayoutConstraint]

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        self.sw = UISwitch()
        self.label = UILabel()
        self.longLabel = UITextView()
        self.cellConstraints = []

        self.constraintsSetForLongLabel = false

        super.init(style: style, reuseIdentifier: reuseIdentifier)

        self.sw.setTranslatesAutoresizingMaskIntoConstraints(false)
        self.label.setTranslatesAutoresizingMaskIntoConstraints(false)
        self.longLabel.setTranslatesAutoresizingMaskIntoConstraints(false)

        self.longLabel.text = nil
        self.longLabel.scrollEnabled = false
        self.longLabel.selectable = false
        self.longLabel.backgroundColor = UIColor.clearColor()

        self.sw.tag = 1
        self.label.tag = 2
        self.longLabel.tag = 3

        self.addSubview(self.sw)
        self.addSubview(self.label)
        self.addSubview(self.longLabel)

        self.addConstraints()
    }

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func addConstraints() {
        let margin: CGFloat = 8
        let sideMargin = margin * 2

        let hasLongText = self.longLabel.text != nil && !self.longLabel.text.isEmpty
        if hasLongText {
            let switchSide = NSLayoutConstraint(item: sw, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: -sideMargin)
            let switchTop = NSLayoutConstraint(item: sw, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: margin)
            let labelSide = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: sideMargin)
            let labelCenter = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: sw, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0)

            self.addConstraint(switchSide)
            self.addConstraint(switchTop)
            self.addConstraint(labelSide)
            self.addConstraint(labelCenter)

            let left = NSLayoutConstraint(item: longLabel, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: sideMargin)
            let right = NSLayoutConstraint(item: longLabel, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: -sideMargin)
            let top = NSLayoutConstraint(item: longLabel, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: sw, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: margin)
            let bottom = NSLayoutConstraint(item: longLabel, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: -margin)

            self.addConstraint(left)
            self.addConstraint(right)
            self.addConstraint(top)
            self.addConstraint(bottom)

            self.cellConstraints += [switchSide, switchTop, labelSide, labelCenter, left, right, top, bottom]

            self.constraintsSetForLongLabel = true
        }
        else {
            let switchSide = NSLayoutConstraint(item: sw, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: -sideMargin)
            let switchTop = NSLayoutConstraint(item: sw, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: margin)
            let switchBottom = NSLayoutConstraint(item: sw, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: -margin)
            let labelSide = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: sideMargin)
            let labelCenter = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: sw, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0)

            self.addConstraint(switchSide)
            self.addConstraint(switchTop)
            self.addConstraint(switchBottom)
            self.addConstraint(labelSide)
            self.addConstraint(labelCenter)

            self.cellConstraints += [switchSide, switchTop, switchBottom, labelSide, labelCenter]

            self.constraintsSetForLongLabel = false
        }
    }

    // XXX: not in updateConstraints because it doesn't play nice with UITableViewAutomaticDimension for some reason
    func changeConstraints() {
        let hasLongText = self.longLabel.text != nil && !self.longLabel.text.isEmpty
        if hasLongText != self.constraintsSetForLongLabel {
            self.removeConstraints(self.cellConstraints)
            self.cellConstraints.removeAll()
            self.addConstraints()
        }

    }



}