尝试访问紧凑模式下的UITextView时,iMessage扩展崩溃
以下是我在iMessage应用程序中的完整代码。
class MessagesViewController: MSMessagesAppViewController { @IBOutlet weak var messageView: UITextView! fileprivate func setupMessageView() { messageView.delegate = self messageView.layer.cornerRadius = 10 messageView.layer.borderColor = UIColor.black.cgColor messageView.layer.borderWidth = 5 messageView.text = "Tap to enter a message" messageView.textColor = UIColor(red:0.80, green:0.81, blue:0.82, alpha:1.0) messageView.textAlignment = .center messageView.font = UIFont.systemFont(ofSize: 20) messageView.textContainerInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10) } func initialize() { setupMessageView() } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { self.view.endEditing(true) } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(self.initialize), userInfo: nil, repeats: false) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // MARK: - Conversation Handling override func willBecomeActive(with conversation: MSConversation) { // Called when the extension is about to move from the inactive to active state. // This will happen when the extension is about to present UI. // Use this method to configure the extension and restore previously stored state. } override func didResignActive(with conversation: MSConversation) { // Called when the extension is about to move from the active to inactive state. // This will happen when the user dissmises the extension, changes to a different // conversation or quits Messages. // Use this method to release shared resources, save user data, invalidate timers, // and store enough state information to restore your extension to its current state // in case it is terminated later. } override func didReceive(_ message: MSMessage, conversation: MSConversation) { // Called when a message arrives that was generated by another instance of this // extension on a remote device. // Use this method to trigger UI updates in response to the message. } override func didStartSending(_ message: MSMessage, conversation: MSConversation) { // Called when the user taps the send button. } override func didCancelSending(_ message: MSMessage, conversation: MSConversation) { // Called when the user deletes the message without sending it. // Use this to clean up state related to the deleted message. } override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) { // Called before the extension transitions to a new presentation style. // Use this method to prepare for the change in presentation style. } override func didTransition(to presentationStyle: MSMessagesAppPresentationStyle) { // Called after the extension transitions to a new presentation style. // Use this method to finalize any behaviors associated with the change in presentation style. } } extension MessagesViewController: UITextViewDelegate { func textViewDidBeginEditing(_ textView: UITextView) { if textView == messageView { requestPresentationStyle(.expanded) if textView.textColor == UIColor(red:0.80, green:0.81, blue:0.82, alpha:1.0) { textView.text = nil textView.textAlignment = .left textView.textColor = UIColor.black textView.font = UIFont.systemFont(ofSize: 20) } } } func textViewDidEndEditing(_ textView: UITextView) { if textView == messageView { if textView.text.isEmpty { textView.text = "Tap to enter a message" textView.textAlignment = .center textView.textColor = UIColor(red:0.80, green:0.81, blue:0.82, alpha:1.0) textView.font = UIFont.systemFont(ofSize: 20) } } } }
它有一个UITextView
,我尝试input数据。 执行此操作时遇到一个奇怪的问题。
在初始加载时,如果我点击UITextView
,扩展模式被调用,但键盘不能向上滑动。 它需要另一个水龙头键盘上滑。
在日志中,我能够发现, textViewDidBeginEditing
和textViewDidEndEditing
方法在第一次敲击时被连续调用。 不知道,为什么这样发生!?
无论如何,更令我感兴趣的是现在发生的事情。 我可以将模式更改为手动压缩,然后重新展开。 如果在扩展模式下,一旦我点击,键盘向上滑动。 但是,如果我在紧凑模式下点击,应用程序崩溃!
而这一直发生。 在模拟器和一个真正的设备。 我无法解释这种行为。
无论多less次将模式从紧凑模式更改为扩展模式,我都可以在扩展模式下input文本。 但是,在第一次敲击之后,它再也不会发生,而在紧凑模式下。
有没有人有这个问题? 或者你可以复制这个? 这是苹果的错误吗?