gpt4 book ai didi

ios - 当我向下移动它的 Y 原点时,UIView 容器消失了

转载 作者:行者123 更新时间:2023-11-29 01:21:14 24 4
gpt4 key购买 nike

我有 UIView,它是按钮“发送”和 textView 的容器。当我开始编辑时,屏幕上有键盘,我更改了容器的 Y 原点以将其移动到更高的位置,而不是被键盘覆盖。

当我完成编辑时,我隐藏了键盘,我的容器(带有按钮和 TextView 的 UIView)就消失了!但是,如果我向右或向左转动模拟器,它就会再次可见。

这是上下移动我的容器的动画代码:

func textViewDidChange(textView: UITextView) {

self.messagePromptLabel.hidden = messageTextView.hasText() ? true : false

}

func textViewDidEndEditing(textView: UITextView) {
if !self.messageTextView.hasText() {
self.messagePromptLabel.hidden = false
}
}

func didTapScrollView(){
self.view.endEditing(true)
}

func keyboardWasShown(notification: NSNotification) {

let dict: NSDictionary = notification.userInfo!
let keyboardSize: NSValue = dict.valueForKey(UIKeyboardFrameEndUserInfoKey) as! NSValue
let frameKeyboardSize: CGRect = keyboardSize.CGRectValue()

UIView.animateWithDuration(0.3, animations: { () -> Void in
self.chatScrollView.frame.origin.y -= frameKeyboardSize.height
self.messageView.frame.origin.y -= frameKeyboardSize.height

}) { (finished: Bool) -> Void in

}

}

func keyboardWillHide(notification: NSNotification) {

UIView.animateWithDuration(0.3, animations: { () -> Void in
self.chatScrollView.frame.origin.y = self.chatScrollViewOriginY!
self.messageView.frame.origin.y = self.messageTextViewOriginY!

}) { (finished: Bool) -> Void in
}
}

一些额外的代码这段代码可能有助于找出一些东西。

@IBOutlet weak var messageTextView: UITextView!
@IBOutlet weak var chatScrollView: UIScrollView!
@IBOutlet weak var messagePromptLabel: UILabel!
@IBOutlet weak var messageView: UIView!

var chatScrollViewOriginY: CGFloat?
var messageTextViewOriginY: CGFloat?

var messageArray = [String]()
var senderArray = [String]()

var currentUserImage: UIImage?
var recipientImage: UIImage?

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
messageTextView.addSubview(messagePromptLabel)
self.title = recipientNickname

chatScrollViewOriginY = self.chatScrollView.frame.origin.y
messageTextViewOriginY = self.messageTextView.frame.origin.y
print(" messageTextViewOriginY \(messageTextViewOriginY)")

NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWasShown:", name: UIKeyboardDidShowNotification, object: nil)

NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "didTapScrollView")
tapGestureRecognizer.numberOfTouchesRequired = 1
chatScrollView.addGestureRecognizer(tapGestureRecognizer)
chatScrollView.backgroundColor = UIColor.redColor()
}

func textViewDidChange(textView: UITextView) {

self.messagePromptLabel.hidden = messageTextView.hasText() ? true : false

}

func textViewDidEndEditing(textView: UITextView) {
if !self.messageTextView.hasText() {
self.messagePromptLabel.hidden = false
}
}

func didTapScrollView(){
self.view.endEditing(true)
}

问题:是什么让我的 UIView 容器在我隐藏键盘时始终不可见,而在我向左或向右转动手机时使其可见?

最佳答案

您需要在发送按钮操作中添加以下代码:

self.view.endEditing(true)

关于ios - 当我向下移动它的 Y 原点时,UIView 容器消失了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34576761/

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