public override void TouchesMoved(Foundation.NSSet touches, UIEvent evt) { base.TouchesMoved(touches, evt); UITouch touch = touches.AnyObject as UITouch; this.touchLocation = touch.LocationInView(this); this.prevTouchLocation = touch.PreviousLocationInView(this); this.SetNeedsDisplay(); }
/// <summary> /// 移动手势,多次调用 /// </summary> /// <param name="touches"></param> /// <param name="evt"></param> public override void TouchesMoved(NSSet touches, UIEvent evt) { base.TouchesMoved(touches, evt); UITouch touch = touches.AnyObject as UITouch; //绘制移动实时路径 this.touchLocation = (PointF)touch.LocationInView(this); this.previousTouchLocation = (PointF)touch.PreviousLocationInView(this); this.SetNeedsDisplay();//更新视图,不断调用Draw方法 }
public override void TouchesMoved(NSSet touches, UIEvent evt) { UITouch touch = (UITouch)touches.AnyObject; UIView.PerformWithoutAnimation(() => { X = X + touch.LocationInView(Screen.GlobalScreen).X - touch.PreviousLocationInView(Screen.GlobalScreen).X; Y = Y + touch.LocationInView(Screen.GlobalScreen).Y - touch.PreviousLocationInView(Screen.GlobalScreen).Y; Clamp(); }); CGPoint newVelocity = CGPoint.Empty; newVelocity.X = touch.LocationInView(Screen.GlobalScreen).X - (nfloat)(touch.PreviousLocationInView(Screen.GlobalScreen).X / (touch.Timestamp - lastTime)); newVelocity.Y = touch.LocationInView(Screen.GlobalScreen).Y - (nfloat)(touch.PreviousLocationInView(Screen.GlobalScreen).Y / (touch.Timestamp - lastTime)); velocity.X = 0.25f * velocity.X + 0.75f * newVelocity.X; velocity.Y = 0.25f * velocity.Y + 0.75f * newVelocity.Y; lastTime = touch.Timestamp; }
public override void TouchesMoved(NSSet touches, UIEvent evt) { base.TouchesMoved(touches, evt); UITouch touch = touches.AnyObject as UITouch; currentPoint = touch.LocationInView(this); previousPoint = touch.PreviousLocationInView(this); SetNeedsDisplay(); }
/// <summary> /// 触屏开始,该方法只会被调用一次(刚就开始触屏的时候) /// </summary> /// <param name="touches"></param> /// <param name="evt"></param> public override void TouchesBegan(NSSet touches, UIEvent evt) { base.TouchesBegan(touches, evt); UITouch touch = touches.AnyObject as UITouch; this.fingerDraw = true; //绘制开始点 this.touchLocation = (PointF)touch.LocationInView(this); this.previousTouchLocation = (PointF)touch.PreviousLocationInView(this); this.SetNeedsDisplay(); //更新视图 }
public override void TouchesMoved(NSSet touches, UIEvent evt) { base.TouchesMoved(touches, evt); UITouch touch = touches.AnyObject as UITouch; var newPoint = touch.LocationInView(this); var previousPoint = touch.PreviousLocationInView(this); nfloat dx = newPoint.X - previousPoint.X; nfloat dy = newPoint.Y - previousPoint.Y; var el = this.Element as BoxViewEx; el.OnManipulationDelta(el, new ManipulationDeltaRoutedEventArgs(el, dx, dy)); }
public override void TouchesBegan(Foundation.NSSet touches, UIEvent evt) { this.OnTapped(new EventArgs()); base.TouchesBegan(touches, evt); path = new UIBezierPath(); UITouch touch = touches.AnyObject as UITouch; this.canTouchDraw = true; this.touchLocation = touch.LocationInView(this); this.prevTouchLocation = touch.PreviousLocationInView(this); this.SetNeedsDisplay(); }
public override void TouchesMoved(NSSet touches, UIEvent evt) { InvokeOnMainThread(() => { UITouch touch = (UITouch)touches.AnyObject; UIView.PerformWithoutAnimation(() => { if (Y < min || Y > max) { Y += 0.5f * (touch.LocationInView(Screen.GlobalScreen).Y - touch.PreviousLocationInView(Screen.GlobalScreen).Y); } else { Y += touch.LocationInView(Screen.GlobalScreen).Y - touch.PreviousLocationInView(Screen.GlobalScreen).Y; } }); double dy = touch.LocationInView(Screen.GlobalScreen).Y - touch.PreviousLocationInView(Screen.GlobalScreen).Y; double dt = touch.Timestamp - lastTime; velocity = velocity * 0.25 + 0.75 * dy / dt; lastTime = touch.Timestamp; }); }
public override void TouchesMoved(NSSet touches, UIEvent evt) { base.TouchesMoved(touches, evt); // get the touch UITouch touch = touches.AnyObject as UITouch; if (touch != null) { // move the shape difference = (float)touch.PreviousLocationInView(this).Y - (float)touch.LocationInView(this).Y; System.Diagnostics.Debug.WriteLine("--------------dif = " + difference); } }
public override void TouchesMoved(NSSet touches, UIEvent evt) { base.TouchesMoved(touches, evt); UITouch touch = touches.AnyObject as UITouch; var newPoint = touch.LocationInView(this); var previousPoint = touch.PreviousLocationInView(this); nfloat offsetX = previousPoint.X - newPoint.X; nfloat offsetY = previousPoint.Y - newPoint.Y; this.Frame = new CoreGraphics.CGRect( this.Frame.X - offsetX, this.Frame.Y - offsetY, this.Frame.Width, this.Frame.Height); }
public override void TouchesMoved(NSSet touches, UIEvent evt) { base.TouchesMoved(touches, evt); // get the touch UITouch touch = touches.AnyObject as UITouch; if (touch != null) { //==== IMAGE TOUCH if (imgTouchMe.Frame.Contains(touch.LocationInView(View))) { lblTouchStatus.Text = "TouchesMoved"; } //==== IMAGE DRAG // check to see if the touch started in the dragme image if (touchStartedInside) { // move the shape nfloat offsetX = touch.PreviousLocationInView(View).X - touch.LocationInView(View).X; nfloat offsetY = touch.PreviousLocationInView(View).Y - touch.LocationInView(View).Y; imgDragMe.Frame = new CGRect(new CGPoint(imgDragMe.Frame.X - offsetX, imgDragMe.Frame.Y - offsetY), imgDragMe.Frame.Size); } } }
public override void TouchesMoved(NSSet touches, UIEvent touchEvent) { directionCacheValid = false; if (panningTouch != null) { CGPoint p0 = panningTouch.PreviousLocationInView(this); CGPoint p1 = panningTouch.LocationInView(this); Controller.PanCamera(new CGSize(p1.X - p0.X, p0.Y - p1.Y)); } if (padTouch != null) { CGPoint p0 = padTouch.PreviousLocationInView(this); CGPoint p1 = padTouch.LocationInView(this); const float speed = 1f / 10f; const float limit = 1f; direction.X += (p1.X - p0.X) * speed; direction.Y += (p1.Y - p0.Y) * speed; if (direction.X > limit) { direction.X = limit; } if (direction.X < -limit) { direction.X = -limit; } if (direction.Y > limit) { direction.Y = limit; } if (direction.Y < -limit) { direction.Y = -limit; } DirectionDidChange(); } base.TouchesMoved(touches, touchEvent); }
void DrawLine(CGContext context, UITouch touch) { var previousLocation = touch.PreviousLocationInView(this); var location = touch.LocationInView(this); context.SetStrokeColor(color.CGColor); width = touch.Force > 0 ? touch.Force * force : force; context.SetLineWidth(width); context.SetLineCap(CGLineCap.Round); context.MoveTo(previousLocation.X, previousLocation.Y); context.AddLineToPoint(location.X, location.Y); context.StrokePath(); }
public override void TouchesMoved(MonoTouch.Foundation.NSSet touches, UIEvent evt) { UITouch touch = (UITouch)touches.AnyObject; if (touch != null) { PointF lastPt = touch.PreviousLocationInView(this); PointF pt = touch.LocationInView(this); float offset = (SplitViewController.Vertical) ? pt.X - lastPt.X : pt.Y - lastPt.Y; if (!SplitViewController.MasterBeforeDetail) { offset = -offset; } SplitViewController.SplitPosition = SplitViewController.SplitPosition + offset; SplitViewController.LayoutSubviews(); } }
public override void TouchesMoved(NSSet touches, UIEvent evt) { base.TouchesMoved(touches, evt); UITouch touch = touches.AnyObject as UITouch; /* MyImageインスタンスの現在の座標 */ var newPoint = touch.LocationInView(this); /* MyImageインスタンスの前回の座標 */ var previousPoint = touch.PreviousLocationInView(this); /* 差分を計算 */ nfloat dx = newPoint.X - previousPoint.X; nfloat dy = newPoint.Y - previousPoint.Y; /* コールバック */ var el = this.Element as MyImage; el.Drug(el, new DrugEventArgs(el, dx, dy)); }
private nfloat LineWidthForShading(CGContext context, UITouch touch) { var previousLocation = touch.PreviousLocationInView(this); var location = touch.LocationInView(this); var vector1 = touch.GetAzimuthUnitVector(this); var vector2 = new CGPoint(location.X - previousLocation.X, location.Y - previousLocation.Y); var angle = Math.Abs(Math.Atan2(vector2.Y, vector2.X) - Math.Atan2(vector1.dy, vector1.dx)); angle = angle > π ? 2 * π - angle : π - angle; var minAngle = 0; var maxAngle = π / 2; var normalizedAngle = (angle - minAngle) / (maxAngle - minAngle); var maxLineWidth = 60; var lineWidth = maxLineWidth * normalizedAngle; var minAltitudeAngle = 0.25; var maxAltitudeAngle = TiltThreshold; var altitudeAngle = Math.Min(minAltitudeAngle, touch.AltitudeAngle); var normalizedAltitude = 1 - ((altitudeAngle - minAltitudeAngle) / (maxAltitudeAngle - minAltitudeAngle)); lineWidth = lineWidth * normalizedAltitude + MinLineWidth; var minForce = 0; var maxForce = 5; var normalizedAlpha = (touch.Force - minForce) / (maxForce - minForce); context.SetAlpha(normalizedAlpha); return((nfloat)lineWidth); }
void TouchesMovedWithEvent(NSSet touches, UIEvent theEvent) { if (touches.Count == 1) { this.TouchCount++; if (this.TouchCount == 3) { if (Math.Abs(this.Center.X - this.OriginalCenter.X) > Math.Abs(this.Center.Y - this.OriginalCenter.Y)) this.MoveLaterally = true; else this.MoveLaterally = false; this.FirstEdgeHit = true; } UITouch touch = touches.AllObjects().FirstObject(); CGPoint center = this.Center; CGPoint currentLoc = touch.LocationInView(this); CGPoint prevLoc = touch.PreviousLocationInView(this); if (this.TouchCount < 3) { center.X += (currentLoc.X - prevLoc.X); center.Y += (currentLoc.Y - prevLoc.Y); } else { if (this.MoveLaterally) { if (currentLoc.X - prevLoc.X < 0.0f && !this.AllowLeft) return; else if (currentLoc.X - prevLoc.X > 0.0f && !this.AllowRight) return; center.X += (currentLoc.X - prevLoc.X); } else { if (currentLoc.Y - prevLoc.Y < 0.0f && !this.AllowUp) return; else if (currentLoc.Y - prevLoc.Y > 0.0f && !this.AllowDown) return; center.Y += (currentLoc.Y - prevLoc.Y); } } this.Center = center; if (this.MoveLaterally) { if ((this.Center.X + this.Frame.Size.Width / 2) > this.Superview.Frame.Size.Width) { this._resetRotation(KSDirection.Right); this.LastDirection = KSDirection.Right; if (this.FirstEdgeHit) { this.FirstEdgeHit = false; this.Shift = new CGPoint(0, 0); } this.Shift.X += (currentLoc.X - prevLoc.X); this._changeViewOpacityForDirection(KSDirection.Right); if (s_hasRightOverlay) { this._showOverlayWithDirectionCurrentLocationPreviousLocation(KSDirection.Right, currentLoc, prevLoc); return; } this.Transform = CGAffineTransform.MakeRotation(Constants.KRotationFactor * this.Shift.X * Math.PI / 180); } else if ((this.Center.X - this.Frame.Size.Width / 2) < 0) { this._resetRotation(KSDirection.Left); this.LastDirection = KSDirection.Left; if (this.FirstEdgeHit) { this.FirstEdgeHit = false; this.Shift = new CGPoint(0, 0); } this.Shift.X += (currentLoc.X - prevLoc.X); this._changeViewOpacityForDirection(KSDirection.Left); if (s_hasLeftOverlay) { this._showOverlayWithDirectionCurrentLocationPreviousLocation(KSDirection.Left, currentLoc, prevLoc); return; } this.Transform = CGAffineTransform.MakeRotation(Constants.KRotationFactor * this.Shift.X * Math.PI / 180); } else { this.Transform = CGAffineTransform.MakeRotation(0); this.Layer.Opacity = 1.0f; this._hideViewOverlays(); } } else { if ((this.Center.Y + this.Frame.Size.Height / 2) > this.Superview.Frame.Size.Height) { if (this.FirstEdgeHit) { this.FirstEdgeHit = false; this.Shift = new CGPoint(0, 0); } this.Shift.Y += (currentLoc.Y - prevLoc.Y); this._changeViewOpacityForDirection(KSDirection.Down); this._showOverlayWithDirectionCurrentLocationPreviousLocation(KSDirection.Down, currentLoc, prevLoc); } else if ((this.Center.Y - this.Frame.Size.Height / 2) < 0) { if (this.FirstEdgeHit) { this.FirstEdgeHit = false; this.Shift = new CGPoint(0, 0); } this.Shift.Y += (currentLoc.Y - prevLoc.Y); this._changeViewOpacityForDirection(KSDirection.Up); this._showOverlayWithDirectionCurrentLocationPreviousLocation(KSDirection.Up, currentLoc, prevLoc); } else { this._hideViewOverlays(); } } } }
public bool UpdateWithTouch(UITouch touch) { if (!touch.EstimationUpdateIndex.IsEqualTo(EstimationUpdateIndex)) { return(false); } // An array of the touch properties that may be of interest. UITouchProperties[] touchProperties = { UITouchProperties.Location, UITouchProperties.Force, UITouchProperties.Altitude, UITouchProperties.Azimuth }; // Iterate through possible properties. foreach (var expectedProperty in touchProperties) { // If an update to this property is not expected, continue to the next property. if (EstimatedPropertiesExpectingUpdates.HasFlag(expectedProperty)) { continue; } switch (expectedProperty) { case UITouchProperties.Force: Force = touch.Force; break; case UITouchProperties.Azimuth: AzimuthAngle = touch.GetAzimuthAngle(touch.View); break; case UITouchProperties.Altitude: AltitudeAngle = touch.AltitudeAngle; break; case UITouchProperties.Location: Location = touch.LocationInView(touch.View); PreciseLocation = touch.PreviousLocationInView(touch.View); break; } // Flag that this point now has a 'final' value for this property. if (!touch.EstimatedProperties.HasFlag(expectedProperty)) { EstimatedProperties &= ~expectedProperty; } // Flag that this point is no longer expecting updates for this property. if (!touch.EstimatedPropertiesExpectingUpdates.HasFlag(expectedProperty)) { EstimatedPropertiesExpectingUpdates &= ~expectedProperty; if (EstimatedPropertiesExpectingUpdates == 0) { PointType &= ~PointType.NeedsUpdate; PointType |= PointType.Updated; } } } return(true); }
void UpdateReticleView (UITouch touch, bool predicated = false) { if (touch == null || touch.Type != UITouchType.Stylus) return; ReticleView.PredictedDotLayer.Hidden = !predicated; ReticleView.PredictedLineLayer.Hidden = !predicated; var azimuthAngle = touch.GetAzimuthAngle (View); var azimuthUnitVector = touch.GetAzimuthUnitVector (View); var altitudeAngle = touch.AltitudeAngle; if (predicated) { ReticleView.PredictedAzimuthAngle = azimuthAngle; ReticleView.PredictedAzimuthUnitVector = azimuthUnitVector; ReticleView.PredictedAltitudeAngle = altitudeAngle; } else { var location = touch.PreviousLocationInView (View); ReticleView.Center = location; ReticleView.ActualAzimuthAngle = azimuthAngle; ReticleView.ActualAzimuthUnitVector = azimuthUnitVector; ReticleView.ActualAltitudeAngle = altitudeAngle; } }
public override bool ContinueTracking(UITouch uitouch, UIEvent uievent) { // PointF previousLocation = uitouch.PreviousLocationInView(this); // PointF currentLocation = uitouch.LocationInView(this); // float trackingOffset = currentLocation.X - previousLocation.X; // // // Find the scrubbing speed that corresponds to the touch's vertical offset // float verticalOffset = Math.Abs(currentLocation.Y - beganTrackingLocation.Y); // int scrubbingSpeedChangePosIndex = IndexOfLowerScrubbingSpeed(_scrubbingSpeedChangePositions, verticalOffset); // if(scrubbingSpeedChangePosIndex == -1) // scrubbingSpeedChangePosIndex = _scrubbingSpeeds.Count; // this.scrubbingSpeed = _scrubbingSpeeds[scrubbingSpeedChangePosIndex - 1]; // // RectangleF trackRect = TrackRectForBounds(Bounds); // this.realPositionValue = this.realPositionValue * (MaxValue - MinValue) * (trackingOffset / trackRect.Size.Width); // // float valueAdjustment = this.scrubbingSpeed * (MaxValue - MinValue) * (trackingOffset / trackRect.Size.Width); // float thumbAdjustment = 0; // if(((this.beganTrackingLocation.Y < currentLocation.Y) && (currentLocation.Y < previousLocation.Y)) || // ((this.beganTrackingLocation.Y > currentLocation.Y) && (currentLocation.Y > previousLocation.Y))) // { // thumbAdjustment = (this.realPositionValue - Value) / (1 + Math.Abs(currentLocation.Y - this.beganTrackingLocation.Y)); // } // Value += valueAdjustment + thumbAdjustment; // // if(Continuous) // SendActionForControlEvents(UIControlEvent.ValueChanged); // // OnContinueTrackingEvent(new EventArgs()); // return Tracking; PointF ptPrev = uitouch.PreviousLocationInView(this); PointF pt = uitouch.LocationInView(this); //float relativeX = pt.X - Frame.X; //float ratioX = relativeX / Frame.Width; float widthWithFinger = Frame.Width + 44; float normalizedX = (pt.X < 0) ? 0 : pt.X; normalizedX = (pt.X > widthWithFinger) ? widthWithFinger : normalizedX; float ratioX = normalizedX / widthWithFinger; // Determine type of scrubbing var scrubbingType = SliderScrubbingType.HighSpeed; if(pt.Y - Frame.Y + Frame.Height > 300) { scrubbingType = SliderScrubbingType.Fine; } else if(pt.Y - Frame.Y + Frame.Height > 200) { scrubbingType = SliderScrubbingType.QuarterSpeed; } else if(pt.Y - Frame.Y + Frame.Height > 100) { scrubbingType = SliderScrubbingType.HalfSpeed; } // Check if event needs to be raised if(scrubbingType != ScrubbingType) { //Console.WriteLine("Slider - Changed scrubbing type to " + scrubbingType.ToString()); ScrubbingType = scrubbingType; OnScrubbingTypeChanged(new EventArgs()); } // Calculate new value float newValueDelta = (ratioX * 10000) - Value; switch(scrubbingType) { case SliderScrubbingType.HalfSpeed: newValueDelta = newValueDelta * 0.5f; break; case SliderScrubbingType.QuarterSpeed: newValueDelta = newValueDelta * 0.25f; break; case SliderScrubbingType.Fine: newValueDelta = newValueDelta * 0.1f; break; } // float newValue = Value + newValueDelta; // if(newValue < MinValue) // newValue = MinValue; // if(newValue > MaxValue) // newValue = MaxValue; // // Value = newValue; // // //SetValue(newValue, true); // Console.WriteLine("Slider - ContinueTracking - newValue: " + newValue.ToString() + " newValueDelta: " + newValueDelta.ToString() + " (" + ptPrev.X.ToString() + ", " + ptPrev.Y.ToString() + ") (" + pt.X.ToString() + ", " + pt.Y.ToString() + ") normalizedX: " + normalizedX.ToString() + " ratioX: " + ratioX.ToString()); // // // // if(Continuous) // SendActionForControlEvents(UIControlEvent.ValueChanged); // // return true; return base.ContinueTracking(uitouch, uievent); }
public bool UpdateWithTouch (UITouch touch) { if (!touch.EstimationUpdateIndex.IsEqualTo(EstimationUpdateIndex)) return false; // An array of the touch properties that may be of interest. UITouchProperties[] touchProperties = { UITouchProperties.Location, UITouchProperties.Force, UITouchProperties.Altitude, UITouchProperties.Azimuth }; // Iterate through possible properties. foreach (var expectedProperty in touchProperties) { // If an update to this property is not expected, continue to the next property. if (EstimatedPropertiesExpectingUpdates.HasFlag (expectedProperty)) continue; switch (expectedProperty) { case UITouchProperties.Force: Force = touch.Force; break; case UITouchProperties.Azimuth: AzimuthAngle = touch.GetAzimuthAngle (touch.View); break; case UITouchProperties.Altitude: AltitudeAngle = touch.AltitudeAngle; break; case UITouchProperties.Location: Location = touch.LocationInView (touch.View); PreciseLocation = touch.PreviousLocationInView (touch.View); break; } // Flag that this point now has a 'final' value for this property. if (!touch.EstimatedProperties.HasFlag (expectedProperty)) EstimatedProperties &= ~expectedProperty; // Flag that this point is no longer expecting updates for this property. if (!touch.EstimatedPropertiesExpectingUpdates.HasFlag (expectedProperty)) { EstimatedPropertiesExpectingUpdates &= ~expectedProperty; if (EstimatedPropertiesExpectingUpdates == 0) { PointType &= ~PointType.NeedsUpdate; PointType |= PointType.Updated; } } } return true; }