本文整理汇总了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 ();
}