在Windows Phone中使用Microsoft.Phone.Controls.Toolkit,在版本为7.0时横屏时屏幕可以正常响应手势事件,而在8.0版本时屏幕就有一部分不能正常响应;麻烦有谁遇到过这种问题的?求解!!!
不支持了,换wp8 Toolkit dll试试。。。实在不行,里面wp8有个demo 拷贝代码就OK
#region UIElement touch event handlers // UIElement.ManipulationStarted indicates the beginning of a touch interaction. It tells us // that we went from having no fingers on the screen to having at least one finger on the screen. // It doesn't tell us what gesture this is going to become, but it can be useful for // initializing your gesture handling code. private void OnManipulationStarted(object sender, ManipulationStartedEventArgs e) { } // UIElement.Tap is used in place of GestureListener.Tap. private void OnTap(object sender, System.Windows.Input.GestureEventArgs e) { transform.TranslateX = transform.TranslateY = 0; } // UIElement.DoubleTap is used in place of GestureListener.DoubleTap. private void OnDoubleTap(object sender, System.Windows.Input.GestureEventArgs e) { //transform.ScaleX = transform.ScaleY = 0; } // UIElement.Hold is used in place of GestureListener.Hold. private void OnHold(object sender, System.Windows.Input.GestureEventArgs e) { transform.TranslateX = transform.TranslateY = 0; transform.ScaleX = transform.ScaleY = 0; transform.Rotation = 0; } // UIElement.ManipulationDelta represents either a drag or a pinch. // If PinchManipulation == null, then we have a drag, corresponding to GestureListener.DragStarted, // GestureListener.DragDelta, or GestureListener.DragCompleted. // If PinchManipulation != null, then we have a pinch, corresponding to GestureListener.PinchStarted, // GestureListener.PinchDelta, or GestureListener.PinchCompleted. // // In this sample we track drag and pinch state to illustrate how to manage transitions between // pinching and dragging, but commonly only the pinch or drag deltas will be of interest, in which // case determining when pinches and drags begin and end is not necessary. // // Note that the exact APIs for the event args are not quite the same as the ones in GestureListener. // Comments inside methods called from here will note where they diverge. private void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e) { bool oldIsPinch = isPinch; bool oldIsDrag = isDrag; isPinch = e.PinchManipulation != null; // The origin of the first manipulation after a pinch is completed always corresponds to the // primary touch point from the pinch, even if the secondary touch point is the one that // remains active. In this sample we only want a drag to affect the rectangle if the finger // on the screen falls inside the rectangle's bounds, so if we've just finished a pinch, // we have to defer until the next ManipulationDelta to determine whether or not a new // drag has started. isDrag = e.PinchManipulation == null && !oldIsPinch; // check for ending gestures if (oldIsDrag && !isDrag) { this.OnDragCompleted(); } if (oldIsPinch && !isPinch) { this.OnPinchCompleted(); } // check for continuing gestures if (oldIsDrag && isDrag) { this.OnDragDelta(sender, e); } if (oldIsPinch && isPinch) { this.OnPinchDelta(sender, e); } // check for starting gestures if (!oldIsDrag && isDrag) { // Once a manipulation has started on the UIElement, that element will continue to fire ManipulationDelta // events until all fingers have left the screen and we get a ManipulationCompleted. In this sample // however, we treat each transition between pinch and drag as a new gesture, and we only want to // apply effects to our border control if the the gesture begins within the bounds of the border. isGestureOnTarget = e.ManipulationContainer == border && new Rect(0, 0, border.ActualWidth, border.ActualHeight).Contains(e.ManipulationOrigin); this.OnDragStarted(); } if (!oldIsPinch && isPinch) { isGestureOnTarget = e.ManipulationContainer == border && new Rect(0, 0, border.ActualWidth, border.ActualHeight).Contains(e.PinchManipulation.Original.PrimaryContact); this.OnPinchStarted(sender, e); } } // UIElement.ManipulationCompleted indicates the end of a touch interaction. It tells us that // we went from having at least one finger on the screen to having no fingers on the screen. // If e.IsInertial is true, then it's also the same thing as GestureListener.Flick, // although the event args API for the flick case are different, as will be noted inside that method. private void OnManipulationCompleted(object sender, ManipulationCompletedEventArgs e) { if (isDrag) { isDrag = false; this.OnDragCompleted(); if (e.IsInertial) { this.OnFlick(sender, e); } } if (isPinch) { isPinch = false; this.OnPinchCompleted(); } } #endregion #region Gesture events inferred from UIElement.Manipulation* touch events private void OnDragStarted() { if (isGestureOnTarget) { //border.Background = greenBrush; } } private void OnDragDelta(object sender, ManipulationDeltaEventArgs e) { // if (isGestureOnTarget) { // HorizontalChange and VerticalChange from DragDeltaGestureEventArgs are now // DeltaManipulation.Translation.X and DeltaManipulation.Translation.Y. // The translation is given in the coordinate space of e.ManipulationContainer, which in // this case is the border control that we're applying transforms to. We need to apply // the the current rotation and scale transforms to the deltas to get back to screen coordinates. // Note that if other ancestors of the border control had transforms applied as well, we would // need to use UIElement.TransformToVisual to get the aggregate transform between // the border control and Application.Current.RootVisual. See GestureListenerStatic.cs in the // WP8 toolkit source for a detailed look at how this can be done. //Point transformedTranslation = GetTransformNoTranslation(transform).Transform(e.DeltaManipulation.Translation); if (e.DeltaManipulation == null) { return; } Point transformedTranslation = e.DeltaManipulation.Translation; transform.TranslateX += initialScale * transformedTranslation.X; transform.TranslateY += initialScale * transformedTranslation.Y; //Debug.WriteLine(transform.TranslateX + "================" + e.PinchManipulation.Current.Scale.X); } } private void OnDragCompleted() { if (isGestureOnTarget) { // border.Background = normalBrush; isDrag = true; isGestureOnTarget = true; } } private void OnPinchStarted(object sender, ManipulationDeltaEventArgs e) { //if (isGestureOnTarget) { initialAngle = transform.Rotation; initialScale = transform.ScaleX; initX = transform.ScaleX; initY = transform.ScaleY; //Debug.WriteLine(initialScale); } } private void OnPinchDelta(object sender, ManipulationDeltaEventArgs e) { // if (isGestureOnTarget) { // Rather than providing the rotation, the event args now just provide // the raw points of contact for the pinch manipulation. // However, calculating the rotation from these two points is fairly trivial; // the utility method used here illustrates how that's done. // Note that we don't have to apply a transform because the angle delta is the // same in any non-skewed reference frame. //double angleDelta = this.GetAngle(e.PinchManipulation.Current) - this.GetAngle(e.PinchManipulation.Original); //transform.Rotation = initialAngle + angleDelta; //// DistanceRatio from PinchGestureEventArgs is now replaced by //// PinchManipulation.DeltaScale and PinchManipulation.CumulativeScale, //// which expose the scale from the pinch directly. //// Note that we don't have to apply a transform because the distance ratio is the //// same in any reference frame. //transform.ScaleX *= e.PinchManipulation.DeltaScale; //transform.ScaleY *= e.PinchManipulation.DeltaScale; if (e.PinchManipulation == null) { return; } //Debug.WriteLine(_image.Width + "------------"); //if (transform.ScaleX < 1) //{ // return; //} double sx = transform.ScaleX; double sy = transform.ScaleY; transform.ScaleX *= e.PinchManipulation.DeltaScale; transform.ScaleY *= e.PinchManipulation.DeltaScale; //transform.ScaleX = transform.ScaleY = initialScale * e.PinchManipulation.DeltaScale; //imgWidth *= transform.ScaleX; // Debug.WriteLine(imgWidth + "----" + transform.ScaleX + "------" + e.PinchManipulation.DeltaScale); //if (transform.ScaleX<1) //{ // imgWidth = 460; // transform.ScaleX = transform.ScaleY = sx; //} //if (transform.ScaleX <= 1) //{ // initXCount -= transform.ScaleX; // if (initXCount < 1) // { // initXCount = 1; // transform.ScaleX = transform.ScaleY = 0; // } //} //else //{ // initXCount += transform.ScaleX; //} } } private void OnPinchCompleted() { if (isGestureOnTarget) { // border.Background = normalBrush; //isPinch = true; //isGestureOnTarget = true; } } private void OnFlick(object sender, ManipulationCompletedEventArgs e) { if (isGestureOnTarget) { // All of the properties on FlickGestureEventArgs have been replaced by the single property // FinalVelocities.LinearVelocity. This method shows how to retrieve from FinalVelocities.LinearVelocity // the properties that used to be in FlickGestureEventArgs. Also, note that while the GestureListener // provided fairly precise directional information, small linear velocities here are rounded // to 0, resulting in flick vectors that are often snapped to one axis. Point transformedVelocity = GetTransformNoTranslation(transform).Transform(e.FinalVelocities.LinearVelocity); double horizontalVelocity = transformedVelocity.X; double verticalVelocity = transformedVelocity.Y; //flickData.Text = string.Format("{0} Flick: Angle {1} Velocity {2},{3}", // this.GetDirection(horizontalVelocity, verticalVelocity), Math.Round(this.GetAngle(horizontalVelocity, verticalVelocity)), horizontalVelocity, verticalVelocity); } } #endregion
是不是wp8 Toolkit dll也不支持?我刚开始使用的是Wp7的dll,更新wp8的dll后就出现问题。
@Aland:支持啊 你dll也要跟着升级才行啊
@walleyekneel: Toolkit这个dll我是已经升级过的,使用的8.0版本的;8.0版本的出现上面的那个问题,横屏是有一半的屏幕响应不到手势;
@Aland: 看我上面方法,那是我从demo截取的,用法跟wp7不一样啦
@walleyekneel: 好的,谢谢
@Aland: 上面代码 我改过一点点,具体参考wp8 demo