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


C# UIPanGestureRecognizer.SetTranslation方法代码示例

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


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

示例1: Panned

        private void Panned(UIPanGestureRecognizer gestureRecognizer)
        {
            if (this.items.Count < 2 || this.contentWidth <= this.View.Bounds.Width)
            {
                return;
            }

            // quick hack for nested panoramas
            if (this.presentedController is UIPanoramaViewController)
            {
                return;
            }

            var panLocation = gestureRecognizer.TranslationInView(this.ContentView);

            var offset = this.currentScrolledOffset - panLocation.X;

            // this is the total amount that we've scrolled away from zero
            this.LayoutContent(this.LimitOffset(offset));

            if (gestureRecognizer.State != UIGestureRecognizerState.Ended)
            {
                return;
            }

            var velocity = gestureRecognizer.VelocityInView(this.View).X;

            if (Math.Abs(velocity) < 700)
            {
                this.currentScrolledOffset = this.CalculatePannedLocation(offset, panLocation.X);
                this.ScrollContent(currentScrolledOffset);
            }
            else
            {
                if (panLocation.X < 0)
                {
                    var proposedOffset = this.GetNextOffset(offset);

                    this.currentScrolledOffset = proposedOffset;
                }
                else
                {
                    var proposedOffset = this.GetPriorOffset(offset);

                    this.currentScrolledOffset = proposedOffset;
                }

                this.ScrollContent(this.currentScrolledOffset);
            }

            gestureRecognizer.SetTranslation(PointF.Empty, this.View);
        }
开发者ID:sgmunn,项目名称:MonoKit.Controls,代码行数:52,代码来源:UIPanoramaViewController.cs

示例2: PanImage

		// Shift the image's center by the pan amount
		void PanImage (UIPanGestureRecognizer gestureRecognizer)
		{
			AdjustAnchorPointForGestureRecognizer (gestureRecognizer);
			var image = gestureRecognizer.View;
			if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed) {
				var translation = gestureRecognizer.TranslationInView (View);
				image.Center = new PointF (image.Center.X + translation.X, image.Center.Y + translation.Y);
				// Reset the gesture recognizer's translation to {0, 0} - the next callback will get a delta from the current position.
				gestureRecognizer.SetTranslation (PointF.Empty, image);
			}
		}
开发者ID:nickoo71,项目名称:monotouch-samples,代码行数:12,代码来源:Touches_GestureRecognizersViewController.cs

示例3: SlideAndFix

		void SlideAndFix (UIPanGestureRecognizer gesture)
		{

			UIView piece = gesture.View;
			nfloat yComponent = piece.Superview.Center.Y - 40f;
			if (!ComponentExpanded || piece.Frame.Top < piece.Superview.Center.Y) {
				ComponentExpanded = true;

			} else {
				yComponent = piece.Superview.Frame.Height - 40f;
				ComponentExpanded = false;
			}

			UIImageView.Animate (
				duration: 0.25f, 
				delay: 0,
				options: UIViewAnimationOptions.TransitionNone,
				animation: () => {
					piece.Frame = new RectangleF (new PointF (piece.Frame.X, yComponent), piece.Frame.Size);

					gesture.SetTranslation (new PointF (0, 0), piece.Superview);
				},
				completion: () => {
					
				});			
		}
开发者ID:TheJaniceTong,项目名称:Judo-Xamarin,代码行数:26,代码来源:SlideUpMenu.cs

示例4: PanGestureMoveAround

		void PanGestureMoveAround (UIPanGestureRecognizer gesture)
		{
			
			UIView piece = gesture.View;

			AdjustAnchorPointForGestureRecognizer (gesture);

			if (gesture.State == UIGestureRecognizerState.Began || gesture.State == UIGestureRecognizerState.Changed) {

				PointF translation = gesture.TranslationInView (piece.Superview);

				piece.Center = new PointF (piece.Center.X, piece.Center.Y + translation.Y);
				 
				gesture.SetTranslation (new PointF (0, 0), piece.Superview);

			} else if (gesture.State == UIGestureRecognizerState.Ended) {
				SlideAndFix (gesture);
			} 		
		}
开发者ID:TheJaniceTong,项目名称:Judo-Xamarin,代码行数:19,代码来源:SlideUpMenu.cs

示例5: moveLine

        void moveLine(UIPanGestureRecognizer gr)
        {
            // if no line selected, do nothing
            if (selectedLine == null)
                return;

            // When the pan gesture recognizer changes its position...
            if (gr.State == UIGestureRecognizerState.Changed) {
                // How far has the pan moved?
                CGPoint translation = gr.TranslationInView(this);

                // Add the translation to the current begin and end points of the line
                CGPoint begin = selectedLine.begin;
                CGPoint end = selectedLine.end;
                begin.X += translation.X;
                begin.Y += translation.Y;
                end.X += translation.X;
                end.Y += translation.Y;

                // Set the new beginning and end points of the line
                selectedLine.begin = begin;
                selectedLine.end = end;

                LineStore.updateCompletedLine(selectedLine);

                this.SetNeedsDisplay();

                gr.SetTranslation(new CGPoint(0,0),this);
            } else if (gr.State == UIGestureRecognizerState.Ended) {
                selectedLine = null;
            }
        }
开发者ID:yingfangdu,项目名称:BNR,代码行数:32,代码来源:TouchDrawView.cs

示例6: 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

示例7: PanGestureRecognized

        void PanGestureRecognized(UIPanGestureRecognizer recognizer)
        {
            //          if ([self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:didRecognizePanGesture:)])
            //              [self.delegate sideMenu:self didRecognizePanGesture:recognizer];

            if (!_panGestureEnabled) {
                return;
            }

            PointF point = recognizer.TranslationInView(View);

            if (recognizer.State == UIGestureRecognizerState.Began) {
                UpdateContentViewShadow();

                _originalPoint = new PointF((float)(_contentViewContainer.Center.X - _contentViewContainer.Bounds.Width / 2.0),
                    (float)(_contentViewContainer.Center.Y - _contentViewContainer.Bounds.Height / 2.0));
                _menuViewContainer.Transform = CGAffineTransform.MakeIdentity();
                if (_scaleBackgroundImageView) {
                    _backgroundImageView.Transform = CGAffineTransform.MakeIdentity();
                    _backgroundImageView.Frame = View.Bounds;
                }
                _menuViewContainer.Frame = View.Bounds;
                AddContentButton();
                View.Window.EndEditing(true);
                _didNotifyDelegate = false;
            }

            if (recognizer.State == UIGestureRecognizerState.Changed) {
                float delta = 0;
                if (Visible) {
                    delta = _originalPoint.X != 0 ? (point.X + _originalPoint.X) / _originalPoint.X : 0;
                } else {
                    delta = point.X / View.Frame.Size.Width;
                }
                delta = Math.Min(Math.Abs(delta), 1.6F);

                float contentViewScale = _scaleContentView ? 1 - ((1 - _contentViewScaleValue) * delta) : 1;

                float backgroundViewScale = 1.7f - (0.7f * delta);
                float menuViewScale = 1.5f - (0.5f * delta);

                if (!_bouncesHorizontally) {
                    contentViewScale = Math.Max(contentViewScale, _contentViewScaleValue);
                    backgroundViewScale = Math.Max(backgroundViewScale, 1.0F);
                    menuViewScale = Math.Max(menuViewScale, 1.0F);
                }

                _menuViewContainer.Alpha = delta;

                if (_scaleBackgroundImageView) {
                    _backgroundImageView.Transform = CGAffineTransform.MakeScale(backgroundViewScale, backgroundViewScale);
                }

                if (_scaleMenuView) {
                    _menuViewContainer.Transform = CGAffineTransform.MakeScale(menuViewScale, menuViewScale);
                }

                if (_scaleBackgroundImageView) {
                    if (backgroundViewScale < 1) {
                        _backgroundImageView.Transform = CGAffineTransform.MakeIdentity();
                    }
                }

                if (!_bouncesHorizontally && Visible) {
                    if (_contentViewContainer.Frame.Location.X > _contentViewContainer.Frame.Size.Width / 2.0)
                        point.X = Math.Min(0.0F, point.X);

                    if (_contentViewContainer.Frame.Location.X < -(_contentViewContainer.Frame.Size.Width / 2.0))
                        point.X = Math.Max(0.0F, point.X);
                }

                // Limit size
                //
                if (point.X < 0) {
                    point.X = Math.Max(point.X, - UIScreen.MainScreen.Bounds.Size.Height);
                } else {
                    point.X = Math.Min(point.X, UIScreen.MainScreen.Bounds.Size.Height);
                }
                recognizer.SetTranslation (point, View);

                if (!_didNotifyDelegate) {
                    if (point.X > 0) {
                        //                      if (!Visible && [self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:willShowMenuViewController:)]) {
                        //                          [self.delegate sideMenu:self willShowMenuViewController:self.leftMenuViewController];
                        //                      }
                    }
                    if (point.X < 0) {

                        //                      if (!self.visible && [self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:willShowMenuViewController:)]) {
                        //                          //[self.delegate sideMenu:self willShowMenuViewController:self.rightMenuViewController];
                        //                      }
                    }
                    _didNotifyDelegate = true;
                }

                if (contentViewScale > 1) {
                    float oppositeScale = (1 - (contentViewScale - 1));
                    _contentViewContainer.Transform = CGAffineTransform.MakeScale(oppositeScale, oppositeScale);
                    _contentViewContainer.Transform = CGAffineTransform.Translate(_contentViewContainer.Transform, point.X, 0);
                } else {
//.........这里部分代码省略.........
开发者ID:rid00z,项目名称:JellyBeanTracker,代码行数:101,代码来源:MRSideMenu.cs

示例8: HandleDrag

        void HandleDrag(UIPanGestureRecognizer sender)
        {
            switch (sender.State)
            {
                case UIGestureRecognizerState.Began:
                    startPos = this.Center;
                // Determines if the view can be pulled in the x or y axis
                    verticalAxis = closedCenter.X == openedCenter.X;
                // Finds the minimum and maximum points in the axis
                    if (verticalAxis)
                    {
                        minPos = closedCenter.Y < openedCenter.Y ? closedCenter : openedCenter;
                        maxPos = closedCenter.Y > openedCenter.Y ? closedCenter : openedCenter;
                    }
                    else
                    {
                        minPos = closedCenter.X < openedCenter.X ? closedCenter : openedCenter;
                        maxPos = closedCenter.X > openedCenter.X ? closedCenter : openedCenter;
                    }
                    break;
                case UIGestureRecognizerState.Changed:
                    PointF translate = sender.TranslationInView(this.Superview);
                    PointF newPos;
                // Moves the view, keeping it constrained between openedCenter and closedCenter
                    if (verticalAxis)
                    {
                        newPos = new PointF(startPos.X, startPos.Y + translate.Y);
                        if (newPos.Y < minPos.Y)
                        {
                            newPos.Y = minPos.Y;
                            translate = new PointF(0, newPos.Y - startPos.Y);
                        }

                        if (newPos.Y > maxPos.Y)
                        {
                            newPos.Y = maxPos.Y;
                            translate = new PointF(0, newPos.Y - startPos.Y);
                        }

                    }
                    else
                    {
                        newPos = new PointF(startPos.X + translate.X, startPos.Y);
                        if (newPos.X < minPos.X)
                        {
                            newPos.X = minPos.X;
                            translate = new PointF(newPos.X - startPos.X, 0);
                        }

                        if (newPos.X > maxPos.X)
                        {
                            newPos.X = maxPos.X;
                            translate = new PointF(newPos.X - startPos.X, 0);
                        }
                    }

                    sender.SetTranslation(translate, this.Superview);
                    this.Center = newPos;
                    break;
                case UIGestureRecognizerState.Ended:
                    PointF vectorVelocity = sender.VelocityInView(this.Superview);
                    float axisVelocity = verticalAxis ? vectorVelocity.Y : vectorVelocity.X;
                    PointF target = axisVelocity < 0 ? minPos : maxPos;
                    bool op = target == openedCenter ? true : false;
                    this.SetOpenedAnimated(op, animate);
                    break;
            }
        }
开发者ID:nodoid,项目名称:pullableview,代码行数:68,代码来源:PullableView.cs

示例9: PanGestureUpdated

        public void PanGestureUpdated(UIPanGestureRecognizer panGesture)
        {
            switch (panGesture.State)
            {
                case UIGestureRecognizerState.Ended:
                case UIGestureRecognizerState.Cancelled:
                case UIGestureRecognizerState.Failed:
                {
                    // TODO:  wtf is this?
                    //[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(transformingGestureDidFinish) object:nil];
                    Selector sel = new Selector("transformingGestureDidFinish");
                    PerformSelector(sel,null,0.1);

                    ScrollEnabled = true;

                } break;
                case UIGestureRecognizerState.Began:
                {
                    TransformingGestureDidBeginWithGesture(panGesture);

                    ScrollEnabled = false;

                } break;
                case UIGestureRecognizerState.Changed:
                {
                    if (panGesture.NumberOfTouches != 2)
                    {
                        panGesture.End();
                    }

                    PointF translate = panGesture.TranslationInView(this);
                    transformingItem.ContentView.Center = new PointF(transformingItem.ContentView.Center.X + translate.X, transformingItem.ContentView.Center.Y + translate.Y);
                    panGesture.SetTranslation(new PointF(),this);

                } break;
                default:
                {
                } break;
            }
        }
开发者ID:skela,项目名称:GMGridView,代码行数:40,代码来源:GridView.cs


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