很长一段时间潜伏 - 第一次海报!
我在重建UITextView像WhatsApp这样的酒吧时遇到了问题.
我正在使用自定义UIView子类,并懒惰地实例化它:
- (UIView *)inputAccessoryView
并返回YES:
- (BOOL)canBecomeFirstResponder
现在,我想改变的大小inputAccessoryView时,UITextView在规模的增长.在iOS 7上,我只是改变所述视图框架的大小 - 而不是它的原点 - 然后调用reloadInputViews它会起作用:视图将向上移动,使其在键盘上方完全可见.
但是,在iOS 8上,这不起作用.使其工作的唯一方法是还将帧的原点更改为负值.这样会很好,除了它会产生一些奇怪的错误:例如,UIView在输入任何文本时返回到"原始"框架.
有什么我想念的吗?我非常肯定WhatsApp使用它inputAccessoryView是因为它们在拖动时解除键盘的方式 - 仅在最新版本的应用程序中.
如果你能帮助我,请告诉我!或者,如果有任何测试,您希望我运行!
谢谢!:)
顺便说一下,这是我用来更新自定义UIView高度的代码composeBar:
// ComposeBar frame size
CGRect frame = self.composeBar.frame;
frame.size.height += heightDifference;
frame.origin.y -= heightDifference;
self.composeBar.frame = frame;
[self.composeBar.textView reloadInputViews]; // Tried with this
[self reloadInputViews]; // and this
Run Code Online (Sandbox Code Playgroud)
编辑:完整源代码可在@ https://github.com/manuelmenzella/SocketChat-iOS获得
我是SWE学习C++,并使用std :: unique_ptr作为head和的引用构建一个简单的LinkedList类next.这是基本结构:
template <class T>
struct LinkedListNode {
T value;
std::unique_ptr<LinkedListNode<T>> next;
// For debugging.
~LinkedListNode() {
std::cout << "destructed for value " << this->value << std::endl;
}
};
template <class T>
struct LinkedList {
std::unique_ptr<LinkedListNode<T>> head;
};
Run Code Online (Sandbox Code Playgroud)
使用智能指针,我希望当LinkedList实例被删除或超出范围时,head将被删除,并且每个next节点也将被递归删除.
这正是发生的事情.但是,当使用很长的列表(大约20M节点)时,它仍然可以正常工作.不应该因堆栈溢出而崩溃吗?
为了非常粗略地估计我的操作系统堆栈的大小,我编写了以下脚本:
int main() {
struct s {
static void p(int i) {
std::cout << i << std::endl;
p(i+1);
};
s::p(0);
}
Run Code Online (Sandbox Code Playgroud)
并且它在迭代次数~175K时崩溃,远远低于之前我能够解除分配的20M节点.到底是怎么回事?我错过了unique_ptr的工作方式吗?