2014-01-27 16 views
0

如何讓雙指縮放X和Y縮放值相互獨立爲Windows Store應用?我目前使用ManipulationDeltaRoutedEventArgsManipulationDelta結構,但你可以看到它只是提供了一個單一的規模。獲得雙指縮放X/Y規模獨立於Windows應用商店的應用程序彼此的價值觀

// Global Transform used to change the position of the Rectangle. 
private TranslateTransform dragTranslation; 
private ScaleTransform scaleTransform; 

// Constructor 
public MainPage() 
{ 
    InitializeComponent(); 

    // Add handler for the ManipulationDelta event 
    TestRectangle.ManipulationDelta += Drag_ManipulationDelta; 
    dragTranslation = new TranslateTransform(); 
    scaleTransform = new ScaleTransform(); 
    TestRectangle.RenderTransform = this.dragTranslation; 
} 

void Drag_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) 
{ 
    // Move the rectangle. 
    dragTranslation.X += e.Delta.Translation.X; 
    dragTranslation.Y += e.Delta.Translation.Y; 

    // Scaling, but I want X and Y independent! 
    scaleTransform.ScaleX = e.Delta.Scale; 
    scaleTransform.ScaleY = e.Delta.Scale; 
} 

XAML:大多來自here採取

<Rectangle Name="TestRectangle" 
    Width="200" Height="200" Fill="Blue" 
    ManipulationMode="All"/> 

代碼。

+1

您可能必須編寫自己的手勢識別器才能做到這一點。幾乎不像聽起來那樣不可能或不可思議。問題是,捏縮放手勢識別目前計算從兩個窄點距離的簡單變化,並有可能不計算方向。採用基礎捏縮放手勢模式,然後將其投影到X和Y軸。 –

+0

作爲一個方面說明,你可能甚至不想這樣做。一些較舊的觸摸屏有問題,當涉及到多點觸控手勢,並在某些情況下甚至做了捏縮放手勢在軸垂直於用戶的實際手指。 – Peping

回答

1

我結束了使用Handling Two, Three, Four Fingers Swipe Gestures in WinRT App抓住兩根手指,計算它們之間的差的初始的座標,然後相應地按比例隨着距離改變。

int numActiveContacts; 
Dictionary<uint, int> contacts; 
List<PointF> locationsOfSortedTouches; 

void myCanvas_PointerPressed(object sender, PointerRoutedEventArgs e) { 
    PointerPoint pt = e.GetCurrentPoint(myCanvas); 
    locationsOfSortedTouches.Add(new PointF((float) pt.Position.X, (float) pt.Position.Y)); 
    touchHandler.TouchesBegan(locationsOfSortedTouches); 
    contacts[pt.PointerId] = numActiveContacts; 
    ++numActiveContacts; 
    e.Handled = true; 
} 

void myCanvas_PointerMoved(object sender, PointerRoutedEventArgs e) { 
    var pt = e.GetCurrentPoint(myCanvas); 
    var ptrId = pt.PointerId; 
    if (contacts.ContainsKey(ptrId)) { 
    var ptrOrdinal = contacts[ptrId]; 
    Windows.Foundation.Point currentContact = pt.Position; 
    locationsOfSortedTouches[ptrOrdinal] = new PointF((float) pt.Position.X, (float) pt.Position.Y); 
    //distance calculation and zoom redraw here 
    } 
    e.Handled = true; 
}