gpt4 book ai didi

ios - 我怎样才能制作表情符号或输入任何内容

转载 作者:搜寻专家 更新时间:2023-11-01 05:40:35 26 4
gpt4 key购买 nike

我目前正在开发自定义键盘当我尝试在新窗口中组合 textDocumentProxy 时遇到问题

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

我尝试输入任何东西,而不仅仅是表情符号

完整的源代码在这里

https://github.com/archagon/tasty-imitation-keyboard

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()
}

}



}

最佳答案

您需要根据您的要求将很多东西更改到您的项目中,例如您可以通过隐藏该 tableView 并在其上添加一个 UIView 来使用该设置 View ,之后您可以将表情符号添加到该 View 中,当用户单击设置按钮时键盘你可以隐藏你的表情符号 View 并显示表格 View 但是当用户想要输入微笑时你不需要隐藏任何东西只需显示你的表情符号 View 。

HERE是您更新的项目。

关于ios - 我怎样才能制作表情符号或输入任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30998714/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com