当前位置: 首页>>代码示例>>C#>>正文


C# UIPanGestureRecognizer.TranslationInView方法代码示例

本文整理汇总了C#中UIPanGestureRecognizer.TranslationInView方法的典型用法代码示例。如果您正苦于以下问题:C# UIPanGestureRecognizer.TranslationInView方法的具体用法?C# UIPanGestureRecognizer.TranslationInView怎么用?C# UIPanGestureRecognizer.TranslationInView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UIPanGestureRecognizer的用法示例。


在下文中一共展示了UIPanGestureRecognizer.TranslationInView方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandlePanGesture

		void HandlePanGesture (UIPanGestureRecognizer gesture)
		{
			if (gesture.State == UIGestureRecognizerState.Began) {
				gestureStartingPoint = gesture.TranslationInView (textView);
				gestureStartingCenter = imageView.Center;
			}
			else if (gesture.State == UIGestureRecognizerState.Changed) {
				CGPoint currentPoint = gesture.TranslationInView(textView);
				nfloat distanceX = currentPoint.X - gestureStartingPoint.X;
				nfloat distanceY = currentPoint.Y - gestureStartingPoint.Y;

				CGPoint newCenter = gestureStartingCenter;

				newCenter.X += distanceX;
				newCenter.Y += distanceY;

				imageView.Center = newCenter;

				textView.TextContainer.ExclusionPaths = TranslatedBezierPath ();
			}
			else if (gesture.State == UIGestureRecognizerState.Ended) {
				gestureStartingPoint  = new CGPoint (0, 0);
				gestureStartingCenter = new CGPoint (0, 0);
			}
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:25,代码来源:ExclusionPathsViewController.cs

示例2: OnPanningGesture

        private void OnPanningGesture (UIPanGestureRecognizer gesture)
        {
            switch (gesture.State) {
            case UIGestureRecognizerState.Began:
                panStart = gesture.TranslationInView (actualContentView);
                panLockInHorizDirection = false;
                break;
            case UIGestureRecognizerState.Changed:
                var currentPoint = gesture.TranslationInView (actualContentView);
                panDeltaX = panStart.X - currentPoint.X;

                if (panDeltaX > 0) {
                    panDeltaX = 0;
                    return;
                }

                if (!panLockInHorizDirection) {
                    if (Math.Abs (panDeltaX) > 30) {
                        // User is swiping the cell, lock them into this direction
                        panLockInHorizDirection = true;
                    } else if (Math.Abs (panStart.Y - currentPoint.Y) > 5) {
                        // User is starting to move upwards, let them scroll
                        gesture.Enabled = false;
                    }
                }

                if (-SwipeWidth > panDeltaX) {
                    panDeltaX = -SwipeWidth;
                }

                UIView.AnimateNotify (0.1, 0, UIViewAnimationOptions.CurveEaseOut, LayoutActualContentView, null);
                break;
            case UIGestureRecognizerState.Ended:
                if (Editing) {
                    break;
                }

                if (!gesture.Enabled) {
                    gesture.Enabled = true;
                }

                var velocityX = gesture.VelocityInView (gesture.View).X;
                var absolutePanDeltaX = Math.Abs (panDeltaX);
                var duration = Math.Max (MinDuration, Math.Min (MaxDuration, (absolutePanDeltaX) / velocityX));

                UIView.AnimateNotify (duration, () => LayoutActualContentView (0), isFinished => {
                    if (isFinished && absolutePanDeltaX > SwipeWidth - 5) {
                        OnContinueGestureFinished ();
                    }
                });

                break;
            case UIGestureRecognizerState.Cancelled:
                UIView.AnimateNotify (0.3, () => LayoutActualContentView (0), isFinished => gesture.Enabled = isFinished);
                break;
            }

        }
开发者ID:BradChang,项目名称:mobile,代码行数:58,代码来源:SwipableTimeEntryTableViewCell.cs

示例3: HandleOnGestureRecognizer

		private void HandleOnGestureRecognizer (UIPanGestureRecognizer gestureRecognizer)
		{
			// The translation of the pan gesture in the coordinate system of the specified view.
			var xTranslation = gestureRecognizer.TranslationInView (this).X;
			var yTranslation = gestureRecognizer.TranslationInView (this).Y;

			if (gestureRecognizer.State.Equals (UIGestureRecognizerState.Began)) {
				_startingPoint = Center;
			} 
			else if (gestureRecognizer.State.Equals (UIGestureRecognizerState.Changed)) {
				var rotationStrength = Math.Min (xTranslation / RotationStrength, 1);
				var rotationAngle = (nfloat)(2 * Math.PI * rotationStrength / 17);
				var scaleStrength = 1 - Math.Abs (rotationStrength) / 4;
				var scale = (nfloat)Math.Max (scaleStrength, ScaleStrength);
				var transform = CGAffineTransform.MakeRotation (rotationAngle);

				Center = new CGPoint (_startingPoint.X + xTranslation, _startingPoint.Y + yTranslation);
				Transform = CGAffineTransform.Scale (transform, scale, scale);
			} 
			else if (gestureRecognizer.State.Equals (UIGestureRecognizerState.Ended)) {
				DetermineSwipeAction (xTranslation);
				ResetView ();
			}
		}
开发者ID:ChandrakanthBCK,项目名称:customer-success-samples,代码行数:24,代码来源:DraggableView.cs

示例4: HandleDrag

        protected void HandleDrag(UIPanGestureRecognizer recognizer)
        {
            // if it's just began, cache the location of the image
            if (recognizer.State == UIGestureRecognizerState.Began)
                originalImageFrame = imgDragMe.Frame;

            if (recognizer.State != (UIGestureRecognizerState.Cancelled | UIGestureRecognizerState.Failed
                | UIGestureRecognizerState.Possible)) {

                // move the shape by adding the offset to the object's frame
                System.Drawing.PointF offset = recognizer.TranslationInView (imgDragMe);
                System.Drawing.RectangleF newFrame = originalImageFrame;
                newFrame.Offset (offset.X, offset.Y);
                imgDragMe.Frame = newFrame;
            }
        }
开发者ID:GSerjo,项目名称:monotouch-samples,代码行数:16,代码来源:GestureRecognizers_iPhone.xib.cs

示例5: HandleGesture

        public void HandleGesture(UIPanGestureRecognizer panGestureRecognizer)
        {
            PointF translation = panGestureRecognizer.TranslationInView (panGestureRecognizer.View.Superview);

            switch (gestureRecognizer.State) {
            case UIGestureRecognizerState.Began:
                TrackGestureBegan (translation);
                break;
            case UIGestureRecognizerState.Changed:
                TrackGestureChaged (translation);
                break;
            case UIGestureRecognizerState.Ended:
            case UIGestureRecognizerState.Cancelled:
                TrackGestureEnded (panGestureRecognizer.State);
                break;
            }
        }
开发者ID:BoogieMAN2K,项目名称:monotouch-samples,代码行数:17,代码来源:CEHorizontalSwipeInteractionController.cs

示例6: HandleDrag

		private void HandleDrag(UIPanGestureRecognizer recognizer)
		{
			// If it's just began, cache the location of the image
			if (recognizer.State == UIGestureRecognizerState.Began)
			{
				originalImageFrame = DragImage.Frame;
			}

			// Move the image if the gesture is valid
			if (recognizer.State != (UIGestureRecognizerState.Cancelled | UIGestureRecognizerState.Failed
				| UIGestureRecognizerState.Possible))
			{
				// Move the image by adding the offset to the object's frame
				CGPoint offset = recognizer.TranslationInView(DragImage);
				CGRect newFrame = originalImageFrame;
				newFrame.Offset(offset.X, offset.Y);
				DragImage.Frame = newFrame;
			}
		}
开发者ID:Rajneesh360Logica,项目名称:monotouch-samples,代码行数:19,代码来源:GestureViewController.cs

示例7: HandleDrag

        //TODO: Step 11b - Provide the handler drag event
        private void HandleDrag(UIPanGestureRecognizer recognizer)
        {
            switch (recognizer.State)
            {
                case UIGestureRecognizerState.Began:
                    // if it's just began, cache the location of the image
                    originalImageFrame = imgDragMe.Frame;
                    break;

                case UIGestureRecognizerState.Possible:
                case UIGestureRecognizerState.Cancelled:
                case UIGestureRecognizerState.Failed:
                    return;
            }

            // move the shape by adding the offset to the object's frame
            PointF offset = recognizer.TranslationInView(imgDragMe);
            var newFrame = originalImageFrame;
            newFrame.Offset(offset.X, offset.Y);
            imgDragMe.Frame = newFrame;
        }
开发者ID:flolovebit,项目名称:xamarin-evolve-2014,代码行数:22,代码来源:GestureRecognizers.cs

示例8: HandleGesture

        public void HandleGesture(UIPanGestureRecognizer gestureRecognizer)
        {
            CGPoint translation = gestureRecognizer.TranslationInView (gestureRecognizer.View.Superview);

            switch (gestureRecognizer.State) {
            case UIGestureRecognizerState.Began:
                bool topToBottomSwipe = translation.Y > 0f;
                if (operation == CEInteractionOperation.Pop) {
                    if (topToBottomSwipe) {
                        InteractionInProgress = true;
                        viewController.NavigationController.PopViewController (true);
                    }
                } else {
                    InteractionInProgress = true;
                    viewController.DismissViewController (true, null);
                }
                break;
            case UIGestureRecognizerState.Changed:
                if (InteractionInProgress) {
                    // compute the current position
                    float fraction = (float)translation.Y / 200f;
                    fraction = Math.Min (Math.Max (fraction, 0f), 1f);
                    shouldCompleteTransition = (fraction > 0.5f);

                    UpdateInteractiveTransition (fraction);
                }
                break;
            case UIGestureRecognizerState.Ended:
            case UIGestureRecognizerState.Cancelled:
                if (InteractionInProgress) {
                    InteractionInProgress = false;
                    if (!shouldCompleteTransition || gestureRecognizer.State == UIGestureRecognizerState.Cancelled) {
                        CancelInteractiveTransition ();
                    } else {
                        FinishInteractiveTransition ();
                    }
                }
                break;
            }
        }
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:40,代码来源:CEVerticalSwipeInteractionController.cs

示例9: HandlePanEnded

        private void HandlePanEnded(UIPanGestureRecognizer gesture)
        {
            var translation = gesture.TranslationInView(_canvasView);

            foreach (var view in _selectedElements)
            {
                var center = view.Center;
                center.X += translation.X;
                center.Y += translation.Y;

                view.Center = center;
            }
        }
开发者ID:TheRealAdamKemp,项目名称:GestureRecognizerPresentation,代码行数:13,代码来源:GestureViewController.cs

示例10: HandlePanChanged

        private void HandlePanChanged(UIPanGestureRecognizer gesture)
        {
            var translation = gesture.TranslationInView(_canvasView);
            var transform = CGAffineTransform.MakeTranslation(translation.X, translation.Y);

            foreach (var view in _selectedElements)
            {
                view.Transform = transform;
            }
        }
开发者ID:TheRealAdamKemp,项目名称:GestureRecognizerPresentation,代码行数:10,代码来源:GestureViewController.cs

示例11: OnPanGesture

        private void OnPanGesture (UIPanGestureRecognizer recognizer)
        {
            var translation = recognizer.TranslationInView (recognizer.View);
            var movement = translation.X - draggingPoint.X;
            var main = window.RootViewController as MainViewController;
            var currentX = main.View.Frame.X;

            switch (recognizer.State) {
            case UIGestureRecognizerState.Began:
                draggingPoint = translation;
                break;

            case UIGestureRecognizerState.Changed:
                var newX = currentX;
                newX += movement;
                if (newX > MinDraggingX && newX < MaxDraggingX) {
                    main.MoveToLocation (newX);
                }
                draggingPoint = translation;
                break;

            case UIGestureRecognizerState.Ended:
                if (Math.Abs (translation.X) >= velocityTreshold) {
                    if (translation.X < 0) {
                        main.CloseMenu ();
                    } else {
                        main.OpenMenu ();
                    }
                } else {
                    if (Math.Abs (currentX) < (View.Frame.Width - menuOffset) / 2) {
                        main.CloseMenu ();
                    } else {
                        main.OpenMenu ();
                    }
                }
                break;
            }
        }
开发者ID:marknotgeorge,项目名称:mobile,代码行数:38,代码来源:LeftViewController.cs

示例12: ResizeRegionOfInterestWithGestureRecognizer

		void ResizeRegionOfInterestWithGestureRecognizer (UIPanGestureRecognizer pan)
		{
			var touchLocation = pan.LocationInView (pan.View);
			var oldRegionOfInterest = RegionOfInterest;

			switch (pan.State) {
			case UIGestureRecognizerState.Began:
				// When the gesture begins, save the corner that is closes to
				// the resize region of interest gesture recognizer's touch location.
				currentControlCorner = CornerOfRect (oldRegionOfInterest, touchLocation);
				break;


			case UIGestureRecognizerState.Changed:
				var newRegionOfInterest = oldRegionOfInterest;

				switch (currentControlCorner) {
				case ControlCorner.None:
					// Update the new region of interest with the gesture recognizer's translation.
					var translation = pan.TranslationInView (pan.View);
					// Move the region of interest with the gesture recognizer's translation.
					if (RegionOfInterest.Contains (touchLocation)) {
						newRegionOfInterest.X += translation.X;
						newRegionOfInterest.Y += translation.Y;
					}

					// If the touch location goes outside the preview layer,
					// we will only translate the region of interest in the
					// plane that is not out of bounds.
					var normalizedRect = new CGRect (0, 0, 1, 1);
					if (!normalizedRect.Contains (VideoPreviewLayer.PointForCaptureDevicePointOfInterest (touchLocation))) {
						if (touchLocation.X < RegionOfInterest.GetMinX () || touchLocation.X > RegionOfInterest.GetMaxX ()) {
							newRegionOfInterest.Y += translation.Y;
						} else if (touchLocation.Y < RegionOfInterest.GetMinY () || touchLocation.Y > RegionOfInterest.GetMaxY ()) {
							newRegionOfInterest.X += translation.X;
						}
					}

					// Set the translation to be zero so that the new gesture
					// recognizer's translation is in respect to the region of
					// interest's new position.
					pan.SetTranslation (CGPoint.Empty, pan.View);
					break;

				case ControlCorner.TopLeft:
					newRegionOfInterest = new CGRect (touchLocation.X, touchLocation.Y,
													 oldRegionOfInterest.Width + oldRegionOfInterest.X - touchLocation.X,
													 oldRegionOfInterest.Height + oldRegionOfInterest.Y - touchLocation.Y);
					break;

				case ControlCorner.TopRight:
					newRegionOfInterest = new CGRect (newRegionOfInterest.X,
												 touchLocation.Y,
												 touchLocation.X - newRegionOfInterest.X,
												 oldRegionOfInterest.Height + newRegionOfInterest.Y - touchLocation.Y);
					break;


				case ControlCorner.BottomLeft:
					newRegionOfInterest = new CGRect (touchLocation.X, oldRegionOfInterest.Y,
												 oldRegionOfInterest.Width + oldRegionOfInterest.X - touchLocation.X,
												 touchLocation.Y - oldRegionOfInterest.Y);
					break;

				case ControlCorner.BottomRight:
					newRegionOfInterest = new CGRect (oldRegionOfInterest.X, oldRegionOfInterest.Y,
												 touchLocation.X - oldRegionOfInterest.X,
												 touchLocation.Y - oldRegionOfInterest.Y);
					break;
				}

				// Update the region of intresest with a valid CGRect.
				SetRegionOfInterestWithProposedRegionOfInterest (newRegionOfInterest);
				break;

			case UIGestureRecognizerState.Ended:
				RegionOfInterestDidChange?.Invoke (this, EventArgs.Empty);

				// Reset the current corner reference to none now that the resize.
				// gesture recognizer has ended.
				currentControlCorner = ControlCorner.None;
				break;

			default:
				return;
			}
		}
开发者ID:xamarin,项目名称:monotouch-samples,代码行数:87,代码来源:PreviewView.cs

示例13: HandlePanSplitter

		void HandlePanSplitter (UIPanGestureRecognizer pan)
		{
			try {
				
				var t = pan.TranslationInView (View);

				if (pan.State == UIGestureRecognizerState.Began) {
					panStartRatio = Ratio;
					Splitter.Touching = true;
				}
				else if (pan.State == UIGestureRecognizerState.Changed) {
					var w = View.Bounds.Width;
					var rr = panStartRatio + t.X / w;
					Ratio = rr;
					containerView.BackgroundColor = First.View.BackgroundColor;
					containerView.SetNeedsLayout ();
				}
				else {
					Splitter.Touching = false;
				}

			} catch (Exception ex) {
				Console.WriteLine (ex);
			}
		}
开发者ID:praeclarum,项目名称:Praeclarum,代码行数:25,代码来源:DynamicSplitViewController.cs

示例14: Pan

        /// <summary>
        /// Pan the specified some.
        /// </summary>
        /// <param name="some">Some.</param>
        private void Pan(UIPanGestureRecognizer pan)
        {
            CGRect rect = this.Frame;
            if (this.MapAllowPan &&
                rect.Width > 0 && this.Map != null)
            {
                this.StopCurrentAnimation();
                CGPoint offset = pan.TranslationInView(this);
                if (pan.State == UIGestureRecognizerState.Ended)
                {
                    this.NotifyMovementByInvoke();

                    // raise map touched event.
                    this.RaiseMapTouched();
                    this.RaiseMapTouchedUp();
                }
                else if (pan.State == UIGestureRecognizerState.Began)
                {
                    _prevOffset = new CGPoint(0, 0);
                    this.RaiseMapTouchedDown();
                }
                else if (pan.State == UIGestureRecognizerState.Changed)
                {
                    View2D view = this.CreateView(rect);
                    double centerXPixels = rect.Width / 2.0f - (offset.X - _prevOffset.X);
                    double centerYPixels = rect.Height / 2.0f - (offset.Y - _prevOffset.Y);

                    _prevOffset = offset;

                    double[] sceneCenter = view.FromViewPort(rect.Width, rect.Height,
                        centerXPixels, centerYPixels);

                    this.MapCenter = this.Map.Projection.ToGeoCoordinates(
                        sceneCenter[0], sceneCenter[1]);

                    this.NotifyMovementByInvoke();

                    // raise map move event.
                    this.RaiseMapMove();
                }
            }
        }
开发者ID:UnifyKit,项目名称:OsmSharp,代码行数:46,代码来源:MapView.cs

示例15: DragContentView

        public void DragContentView(UIPanGestureRecognizer panGesture)
        {
            if (ShouldStayOpen || mainView == null)
                return;
            RectangleF frame = mainView.Frame;
            float translation = panGesture.TranslationInView(View).X;
            //Console.WriteLine (translation);

            if (panGesture.State == UIGestureRecognizerState.Began)
            {
                startX = frame.X;
            }
            else if (panGesture.State == UIGestureRecognizerState.Changed)
            {
                frame.X = translation + startX;
                if (frame.X < 0)
                    frame.X = 0;
                else if (frame.X > frame.Width)
                    frame.X = menuWidth;
                SetLocation(frame);
            }
            else if (panGesture.State == UIGestureRecognizerState.Ended)
            {
                float velocity = panGesture.VelocityInView(View).X;
                //Console.WriteLine (velocity);
                float newX = translation + startX;
                Console.WriteLine(translation + startX);
                bool show = (Math.Abs(velocity) > sidebarFlickVelocity)
                                ? (velocity > 0)
                                : startX < menuWidth ? (newX > (menuWidth/2)) : newX > menuWidth;
                if (show)
                    ShowMenu();
                else
                    HideMenu();
            }
        }
开发者ID:schmidan,项目名称:FlyoutNavigation,代码行数:36,代码来源:FlyoutNavigationController.cs


注:本文中的UIPanGestureRecognizer.TranslationInView方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。