private void PinchGestureRecognizerHandler(UIPinchGestureRecognizer gestureRecognizer) { Stopwatch sw = Stopwatch.StartNew(); RefreshArguments arguments = CollectArguments(gestureRecognizer); if (middlePoint.Equals(CGPoint.Empty)) { if (gestureRecognizer.NumberOfTouches <= 1) { return; } CGPoint point1 = gestureRecognizer.LocationOfTouch(0, containerView); CGPoint point2 = gestureRecognizer.LocationOfTouch(1, containerView); nfloat x = point1.X - point2.X; nfloat y = point1.Y - point2.Y; middlePoint = new CGPoint(point1.X + x, point1.Y + y); } if (tileSize == 0) { zoomLevel = arguments.ZoomLevel; tileSize = arguments.TileSize; extentWidth = containerView.CurrentExtent.Width; extentHeight = containerView.CurrentExtent.Height; } arguments.Scale = gestureRecognizer.Scale; arguments.ZoomLevel = zoomLevel * gestureRecognizer.Scale; arguments.TileSize = (int)(tileSize * gestureRecognizer.Scale); txtZoomLevel.Text = arguments.ZoomLevel.ToString(); txtTileSize.Text = arguments.TileSize.ToString(); nfloat newLeft = middlePoint.X - gestureRecognizer.Scale * middlePoint.X; nfloat newTop = middlePoint.Y - gestureRecognizer.Scale * middlePoint.Y; nfloat newWidth = extentWidth * gestureRecognizer.Scale; nfloat newHeight = extentHeight * gestureRecognizer.Scale; containerView.CurrentExtent = new CGRect(newLeft, newTop, newWidth, newHeight); containerView.RefreshZoomTileView(arguments); if (gestureRecognizer.State == UIGestureRecognizerState.Ended) { middlePoint = CGPoint.Empty; zoomLevel = 0.0f; tileSize = 0; extentWidth = 0.0f; extentHeight = 0.0f; } sw.Stop(); GestureTimeMonitorAction(sw.ElapsedMilliseconds); }
/// <summary> /// Points the inside. /// </summary> /// <returns><c>true</c>, if inside was pointed, <c>false</c> otherwise.</returns> /// <param name="point">Point.</param> /// <param name="_event">With Event</param> bool PointInside(CGPoint point, UIEvent _event) { // Return NO if even super returns NO (i.e., if point lies outside our bounds) bool superResult = base.PointInside(point, _event); if (!superResult) { return(superResult); } // Don't check again if we just queried the same point // (because pointInside:withEvent: gets often called multiple times) if (point.Equals(previousTouchPoint)) { return(previousTouchHitTestResponse); } else { previousTouchPoint = point; } bool response = false; if (buttonImage == null && buttonBackground == null) { response = true; } else if (buttonImage != null && buttonBackground == null) { response = IsAlphaVisibleAtPoint(point, buttonImage); } else if (buttonImage == null && buttonBackground != null) { response = IsAlphaVisibleAtPoint(point, buttonBackground); } else { if (IsAlphaVisibleAtPoint(point, buttonImage)) { response = true; } else { response = IsAlphaVisibleAtPoint(point, buttonBackground); } } previousTouchHitTestResponse = response; return(response); }
private RefreshArguments CollectArguments(UIGestureRecognizer e) { RefreshArguments arguments = new RefreshArguments(); arguments.ZoomLevel = double.Parse(txtZoomLevel.Text); arguments.TileSize = int.Parse(txtTileSize.Text); CGPoint location = e.LocationInView(containerView); if (startPoint.Equals(CGPoint.Empty)) { startPoint = location; } arguments.OffsetX = location.X - startPoint.X; arguments.OffsetY = location.Y - startPoint.Y; startPoint = location; return(arguments); }
/// <summary> /// Animates the focal target. /// </summary> /// <param name="touchPoint">Touch point.</param> private void AnimateFocalTarget(CGPoint touchPoint) { var changed = !_touchPoint.Equals(touchPoint); _touchPoint = touchPoint; BeginAnimations("AnimateFocalTarget"); if (changed) { _locationTargetImageView.Alpha = 0.0f; _locationPlaceholderImageView.Alpha = 0.0f; _locationPlaceholderImageView.Frame = new CGRect(0, 0, 200, IMG_TARGET_BOUND); } _locationTargetImageView.Frame = new CGRect(touchPoint.X - (IMG_TARGET_BOUND / 2), touchPoint.Y - (IMG_TARGET_BOUND / 2), IMG_TARGET_BOUND, IMG_TARGET_BOUND); Animate(1, 0, UIViewAnimationOptions.CurveEaseIn, () => { _locationTargetImageView.Alpha = 1.0f; }, () => { Animate(0.25, 0, UIViewAnimationOptions.CurveEaseIn, () => { var targetFrame = new CGRect(touchPoint.X - (IMG_TARGET_BOUND / 4), touchPoint.Y - (IMG_TARGET_BOUND / 4), (IMG_TARGET_BOUND / 2), (IMG_TARGET_BOUND / 2)); // add placeholder frame to the right of target with spacing _locationTargetImageView.Frame = targetFrame; var placeholderFrame = _locationPlaceholderImageView.Frame; if (changed) { // if target is to the left of the middle, place placeholder to the right, // and vice versa if (targetFrame.X < (this.Bounds.Width / 2)) { placeholderFrame.X += targetFrame.X + targetFrame.Width + 20; _locationPlaceholderImageView.Transform = CGAffineTransform.MakeScale(1, 1); } else { placeholderFrame.X += targetFrame.X - (placeholderFrame.Width + 25); _locationPlaceholderImageView.Transform = CGAffineTransform.MakeScale(-1, 1); } placeholderFrame.Y += targetFrame.Y - (targetFrame.Height / 2); var labelFrame = placeholderFrame; labelFrame.X += 27; labelFrame.Width -= 27; _locationPlaceholderImageView.Frame = placeholderFrame; _locationPlaceholderLabel.Frame = labelFrame; _locationPlaceholderLabel.Alpha = 1.0f; _locationPlaceholderImageView.Alpha = 1.0f; } }, null); }); CommitAnimations(); _isAnimating = false; }