gpt4 book ai didi

ios - 如何使 PHFComposeBarView 控件在 Swift iOS 应用程序中变为事件状态?

转载 作者:可可西里 更新时间:2023-11-01 02:20:07 25 4
gpt4 key购买 nike

作为 iOS 开发的相对菜鸟,我正在努力制作 PHFComposeBarView控件在我的 Swift iOS 应用程序中变为事件状态。

斜眼看着 PHFComposeBarView example app 中的 Obj-C和 this SO answer ,我已尽我所能将基本设置转换为 Swift,以便控件显示在主视图中:

enter image description here

但是,我还没有设法使控件以编程方式激活。

我创建了一个 minimal test case project在 Swift 2.0/XCode 7.0 Beta 2 中,其 ViewController 如下所示:

ViewController.swift:

import UIKit
import PHFComposeBarView

class ViewController: UIViewController, PHFComposeBarViewDelegate {

var composeBar: PHFComposeBarView {
let viewBounds = self.view.bounds
let frame = CGRectMake(0.0, viewBounds.size.height - PHFComposeBarViewInitialHeight, viewBounds.size.width, PHFComposeBarViewInitialHeight)
let composeBarView = PHFComposeBarView(frame: frame)
composeBarView.delegate = self
return composeBarView
}

override var inputAccessoryView: UIView {
return self.composeBar
}

override func canBecomeFirstResponder() -> Bool {
return true
}

override func viewDidAppear(animated: Bool) {
print("viewDidAppear self \(self)")
print("composeBar.delegate \(self.composeBar.delegate)")
print("composeBar.textView.delegate \(self.composeBar.textView.delegate)")
print("composeBar.canBecomeFirstResponder() \(self.composeBar.canBecomeFirstResponder())")
print("composeBar.textView.canBecomeFirstResponder() \(self.composeBar.textView.canBecomeFirstResponder())")
let res = self.composeBar.becomeFirstResponder()
print("composeBar.becomeFirstResponder() \(res)")
print("composeBar.isFirstResponder() \(self.composeBar.isFirstResponder())")
print("composeBar.textView.isFirstResponder() \(self.composeBar.textView.isFirstResponder())")
}

}

控制台:

viewDidAppear self <SwiftPHFComposeBarTest.ViewController: 0x7fe088619d90>
composeBar.delegate Optional(<SwiftPHFComposeBarTest.ViewController: 0x7fe088619d90>)
composeBar.textView.delegate Optional(<PHFDelegateChain: 0x7fe088654850>)
composeBar.canBecomeFirstResponder() true
composeBar.textView.canBecomeFirstResponder() true
composeBar.becomeFirstResponder() false
composeBar.isFirstResponder() false
composeBar.textView.isFirstResponder() false

怎么可能 composeBar.canBecomeFirstResponder() 返回 truecomposeBar.becomeFirstResponder() 返回 false?

另外,我不确定委托(delegate)是可选的是否有问题。

编辑:更新为包含调试输出。

最佳答案

好吧,一个解决方案似乎是 use the storyboard instead :

ViewController.swift:

import UIKit
import PHFComposeBarView

class ViewController: UIViewController, PHFComposeBarViewDelegate {

@IBOutlet weak var composeBarView: PHFComposeBarView!

override func viewDidLoad() {
super.viewDidLoad()
composeBarView.delegate = self
}

override func canBecomeFirstResponder() -> Bool {
return true
}

override var inputAccessoryView: UIView {
composeBarView.removeFromSuperview()
return composeBarView
}

}

Screenshot

关于ios - 如何使 PHFComposeBarView 控件在 Swift iOS 应用程序中变为事件状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31246045/

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