在我的移动safari项目中,我需要创建一个消息发布功能。当文本行数超过文本区域的最大行数时,需要在文本区域内滚动。我在Ext.field.textarea中找不到"可滚动"属性,知道怎么做吗?干杯
touch 2.0.x中存在一个错误,因此框架明确阻止了滚动操作。据推测,2.1中会有一个修复程序,尽管我没有正式看到,只是从论坛上的一个家伙那里看到的。
在此之前,这里有一种针对touch1的解决方案http://www.sencha.com/forum/showthread.php?180207-iOS上的文本区域滚动不起作用,您可以将其移植到V2。它基本上包括向实际的文本区域字段(而不是sencha对象)添加一个eventlistener,然后如果它是一个有效的滚动事件,则调用preventdefault。
完整的代码在那个链接上,但重要的部分在这里。
抓住<text区域>字段(不是Sencha Touch对象),并使用addListener应用touchstart上的handleTouch和touchmove 上的handleMove
handleTouch: function(e) {
this.lastY = e.pageY;
},
handleMove: function(e) {
var textArea = e.target;
var top = textArea.scrollTop <= 0;
var bottom = textArea.scrollTop + textArea.clientHeight >= textArea.scrollHeight;
var up = e.pageY > this.lastY;
var down = e.pageY < this.lastY;
this.lastY = e.pageY;
// default (mobile safari) action when dragging past the top or bottom of a scrollable
// textarea is to scroll the containing div, so prevent that.
if((top && up) || (bottom && down)) {
e.preventDefault();
e.stopPropagation(); // this tops scroll going to parent
}
// Sencha disables textarea scrolling on iOS by default,
// so stop propagating the event to delegate to iOS.
if(!(top && bottom)) {
e.stopPropagation(); // this tops scroll going to parent
}
}
Ext.define('Aspen.util.TextArea', {
override: 'Ext.form.TextArea',
adjustHeight: Ext.Function.createBuffered(function (textarea) {
var textAreaEl = textarea.getComponent().input;
if (textAreaEl) {
textAreaEl.dom.style.height = 'auto';
textAreaEl.dom.style.height = textAreaEl.dom.scrollHeight + "px";
}
}, 200, this),
constructor: function () {
this.callParent(arguments);
this.on({
scope: this,
keyup: function (textarea) {
textarea.adjustHeight(textarea);
},
change: function (textarea, newValue) {
textarea.adjustHeight(textarea);
}
});
}
});