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


C# CGRect.Standardize方法代码示例

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


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

示例1: SetRegionOfInterestWithProposedRegionOfInterest

		// Updates the region of interest with a proposed region of interest ensuring
		// the new region of interest is within the bounds of the video preview. When
		// a new region of interest is set, the region of interest is redrawn.
		public void SetRegionOfInterestWithProposedRegionOfInterest (CGRect proposedRegionOfInterest)
		{
			// We standardize to ensure we have positive widths and heights with an origin at the top left.
			var videoPreviewRect = VideoPreviewLayer.MapToLayerCoordinates (new CGRect (0, 0, 1, 1)).Standardize ();

			// Intersect the video preview view with the view's frame to only get
			// the visible portions of the video preview view.
			var visibleVideoPreviewRect = CGRect.Intersect (videoPreviewRect, Frame);
			var oldRegion = RegionOfInterest;
			var newRegion = proposedRegionOfInterest.Standardize ();

			// Move the region of interest in bounds.
			if (currentControlCorner == ControlCorner.None) {
				nfloat xOffset = 0;
				nfloat yOffset = 0;

				if (!visibleVideoPreviewRect.Contains (newRegion.CornerTopLeft())) {
					xOffset = NMath.Max (visibleVideoPreviewRect.GetMinX () - newRegion.GetMinX (), 0);
					yOffset = NMath.Max (visibleVideoPreviewRect.GetMinY () - newRegion.GetMinY (), 0);
				}

				if (!visibleVideoPreviewRect.Contains (visibleVideoPreviewRect.CornerBottomRight())) {
					xOffset = NMath.Min (visibleVideoPreviewRect.GetMaxX () - newRegion.GetMaxX (), xOffset);
					yOffset = NMath.Min (visibleVideoPreviewRect.GetMaxY () - newRegion.GetMaxY (), yOffset);
				}

				newRegion.Offset (xOffset, yOffset);
			}

			// Clamp the size when the region of interest is being resized.
			visibleVideoPreviewRect.Intersect(newRegion);
			newRegion = visibleVideoPreviewRect;

			// Fix a minimum width of the region of interest.
			if (proposedRegionOfInterest.Size.Width < MinimumRegionOfInterestSize) {
				switch (currentControlCorner) {
				case ControlCorner.TopLeft:
				case ControlCorner.BottomLeft:
					var x = oldRegion.Location.X + oldRegion.Size.Width - MinimumRegionOfInterestSize;
					newRegion = newRegion.WithX (x).WithWidth (MinimumRegionOfInterestSize);
					break;

				case ControlCorner.TopRight:
					newRegion = newRegion.WithX (oldRegion.Location.X)
										 .WithWidth (MinimumRegionOfInterestSize);
					break;

				default:
					newRegion = newRegion.WithLocation (oldRegion.Location)
										 .WithWidth (MinimumRegionOfInterestSize);
					break;
				}
			}

			// Fix a minimum height of the region of interest.
			if (proposedRegionOfInterest.Height < MinimumRegionOfInterestSize) {
				switch (currentControlCorner) {
				case ControlCorner.TopLeft:
				case ControlCorner.TopRight:
					newRegion = newRegion.WithY (oldRegion.Y + oldRegion.Height - MinimumRegionOfInterestSize)
										 .WithHeight (MinimumRegionOfInterestSize);
					break;

				case ControlCorner.BottomLeft:
					newRegion = newRegion.WithY (oldRegion.Y)
										 .WithHeight (MinimumRegionOfInterestSize);
					break;

				default:
					newRegion = newRegion.WithLocation (oldRegion.Location)
										 .WithHeight (MinimumRegionOfInterestSize);
					break;
				}
			}

			RegionOfInterest = newRegion;
			SetNeedsLayout ();
		}
开发者ID:xamarin,项目名称:monotouch-samples,代码行数:81,代码来源:PreviewView.cs


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