2012-07-25 110 views

回答

3

有聯繫2.0.x的一個bug使得框架明確地防止滾動操作。據說一個修補程序將在2.1,雖然我沒有正式看到,只是從一個論壇上的人。

在此之前,有一種用於touch1解決這裏http://www.sencha.com/forum/showthread.php?180207-TextArea-scroll-on-iOS-not-working,你可以移植到V2。它基本上包括將一個事件偵聽到實際textarea的領域(不是煎茶對象),然後調用了preventDefault如果它是一個有效的表示ScrollEvent。

完整的代碼是在那個環節,但突出的位都在這裏。

抓住< textarea的>字段(不是煎茶觸摸對象)直接使用addListener申請 'handleTouch' 上touchstart和 'handleMove' 上touchmove

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 
    } 
} 
0
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); 
     } 
    }); 
} 

});

相關問題