2017-02-28 54 views
1

我想爲Flickable創建某種形式的視覺「反彈邊緣」效果。但是這個邊緣是一個很堅硬的邊緣,就像一堵牆一樣,所以內容不能隨時被拖拽或滑過。Qt QML。如何讓Flickable的內容反彈而不超過它?

下面是一些代碼,我設置了StopAtBounds,但後來我不能使用反彈轉換。

import QtQuick 2.7 
import QtQuick.Controls 1.4 

ApplicationWindow 
{ 
    visible: true 
    width: 800 
    height: 800 

    Flickable 
    { 
     anchors.fill: parent 

     contentWidth: bob.width 
     contentHeight: bob.height 

     rightMargin: 200 
     leftMargin: 200 
     topMargin: 200 
     bottomMargin: 200 

     // prevents bob from going outside of bounds, 
     // but now cant use `rebound` transition. 
     // so how to apply `Easing.OutBounce` 
     boundsBehavior: Flickable.StopAtBounds 

     Rectangle 
     { 
      id: bob 
      width: 600 
      height: 600 
      color: "red" 
     } 
    } 
} 

您可以輕彈紅場和它擊中牆壁,但它不反彈。

有什麼建議嗎?

+0

我不認爲'Flickable'是針對這種類型的行爲製作的,也不支持自定義行爲。 –

+0

還沒有,至少:https://bugreports.qt.io/browse/QTBUG-38515 – GrecKo

回答

0

您試過 boundsBehavior: Flickable.OvershootBounds

它可以讓你在彈跳的邊界附近彈跳過渡。唯一的問題是該元素可能會略微超出限制。

看起來像Flickable.StopAtBounds確實如此說:停止元素在邊界沒有反彈動畫。

+0

是的,但它稍微在外面。這是我的問題。不管怎麼說,還是要謝謝你。 –

相關問題