本文整理汇总了C#中CGRect类的典型用法代码示例。如果您正苦于以下问题:C# CGRect类的具体用法?C# CGRect怎么用?C# CGRect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CGRect类属于命名空间,在下文中一共展示了CGRect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NativeArrange
protected override void NativeArrange(CGRect finalRect)
{
this.ScrollView.ContentSize = finalRect.Size;
// That's right. We don't need to rearrange page;
////base.NativeArrange(finalRect);
}
示例2: ShareUrl
public void ShareUrl(object sender, Uri uri)
{
var item = new NSUrl(uri.AbsoluteUri);
var activityItems = new NSObject[] { item };
UIActivity[] applicationActivities = null;
var activityController = new UIActivityViewController (activityItems, applicationActivities);
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
{
var window = UIApplication.SharedApplication.KeyWindow;
var pop = new UIPopoverController (activityController);
var barButtonItem = sender as UIBarButtonItem;
if (barButtonItem != null)
{
pop.PresentFromBarButtonItem(barButtonItem, UIPopoverArrowDirection.Any, true);
}
else
{
var rect = new CGRect(window.RootViewController.View.Frame.Width / 2, window.RootViewController.View.Frame.Height / 2, 0, 0);
pop.PresentFromRect (rect, window.RootViewController.View, UIPopoverArrowDirection.Any, true);
}
}
else
{
var viewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
viewController.PresentViewController(activityController, true, null);
}
}
示例3: SetupOutlineView
// This sets up a NSOutlineView for demonstration
internal static NSView SetupOutlineView (CGRect frame)
{
// Create our NSOutlineView and set it's frame to a reasonable size. It will be autosized via the NSClipView
NSOutlineView outlineView = new NSOutlineView () {
Frame = frame
};
// Every NSOutlineView must have at least one column or your Delegate will not be called.
NSTableColumn column = new NSTableColumn ("Values");
outlineView.AddColumn (column);
// You must set OutlineTableColumn or the arrows showing children/expansion will not be drawn
outlineView.OutlineTableColumn = column;
// Setup the Delegate/DataSource instances to be interrogated for data and view information
// In Unified, these take an interface instead of a base class and you can combine these into
// one instance.
outlineView.Delegate = new OutlineViewDelegate ();
outlineView.DataSource = new OutlineViewDataSource ();
// NSOutlineView expects to be hosted inside an NSClipView and won't draw correctly otherwise
NSClipView clipView = new NSClipView (frame) {
AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable
};
clipView.DocumentView = outlineView;
return clipView;
}
示例4: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
// Create the chart
View.BackgroundColor = UIColor.White;
nfloat margin = UserInterfaceIdiomIsPhone ? 10 : 50;
CGRect frame = new CGRect (margin, margin, View.Bounds.Width - 2 * margin, View.Bounds.Height - 2 * margin);
chart = new ShinobiChart (frame) {
Title = "Apple Stock Price",
AutoresizingMask = ~UIViewAutoresizing.None,
LicenseKey = "" // TODO: add your trail licence key here!
};
// Add a discountinuous date axis
chart.XAxis = new SChartDateTimeAxis () {
Title = "Date",
EnableGesturePanning = true,
EnableGestureZooming = true
};
chart.YAxis = new SChartNumberAxis () {
Title = "Price (USD)",
EnableGesturePanning = true,
EnableGestureZooming = true
};
// Add to the view
View.AddSubview (chart);
chart.DataSource = new CandlestickChartDataSource ();
}
示例5: AddBox
private void AddBox (string title, CGRect frame, int level, NSColor color)
{
var node = Utils.SCBoxNode (title, frame, color, 2.0f, true);
node.Scale = new SCNVector3 (0.02f, 0.02f, 0.02f);
node.Position = new SCNVector3 (-5, 1.5f * level, 10);
ContentNode.AddChildNode (node);
}
示例6: AnimationForSeries
public override CAAnimation AnimationForSeries(TKChart chart, TKChartSeries series, TKChartSeriesRenderState state, CGRect rect)
{
double duration = 0.5;
List<CAAnimation> animations = new List<CAAnimation> ();
for (int i = 0; i<(int)state.Points.Count; i++) {
string keyPath = string.Format ("seriesRenderStates.{0}.points.{1}.y", series.Index, i);
TKChartVisualPoint point = (TKChartVisualPoint)state.Points.ObjectAtIndex((uint)i);
double oldY = rect.Height;
double half = oldY + (point.Y - oldY)/2.0;
CAKeyFrameAnimation a = (CAKeyFrameAnimation)CAKeyFrameAnimation.GetFromKeyPath(keyPath);
a.KeyTimes = new NSNumber[] { new NSNumber (0), new NSNumber (0), new NSNumber (1) };
a.Values = new NSObject[] { new NSNumber (oldY), new NSNumber (half), new NSNumber (point.Y) };
a.Duration = duration;
a.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.EaseOut);
animations.Add(a);
}
CAAnimationGroup group = new CAAnimationGroup ();
group.Duration = duration;
group.Animations = animations.ToArray();
return group;
}
示例7: MyOpenGLView
public MyOpenGLView (CGRect frame,NSOpenGLContext context) : base(frame)
{
var attribs = new object [] {
NSOpenGLPixelFormatAttribute.Accelerated,
NSOpenGLPixelFormatAttribute.NoRecovery,
NSOpenGLPixelFormatAttribute.DoubleBuffer,
NSOpenGLPixelFormatAttribute.ColorSize, 24,
NSOpenGLPixelFormatAttribute.DepthSize, 16 };
pixelFormat = new NSOpenGLPixelFormat (attribs);
if (pixelFormat == null)
Console.WriteLine ("No OpenGL pixel format");
// NSOpenGLView does not handle context sharing, so we draw to a custom NSView instead
openGLContext = new NSOpenGLContext (pixelFormat, context);
openGLContext.MakeCurrentContext ();
// Synchronize buffer swaps with vertical refresh rate
openGLContext.SwapInterval = true;
// Initialize our newly created view.
InitGL ();
SetupDisplayLink ();
// Look for changes in view size
// Note, -reshape will not be called automatically on size changes because NSView does not export it to override
notificationProxy = NSNotificationCenter.DefaultCenter.AddObserver (NSView.GlobalFrameChangedNotification, HandleReshape);
}
示例8: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// set the background color of the view to white
View.BackgroundColor = UIColor.White;
// instantiate a new image view that takes up the whole screen and add it to
// the view hierarchy
CGRect imageViewFrame = new CGRect (0, -NavigationController.NavigationBar.Frame.Height, View.Frame.Width, View.Frame.Height);
imageView = new UIImageView (imageViewFrame);
View.AddSubview (imageView);
// create our offscreen bitmap context
// size
CGSize bitmapSize = new CGSize (imageView.Frame.Size);
using (CGBitmapContext context = new CGBitmapContext (IntPtr.Zero,
(int)bitmapSize.Width, (int)bitmapSize.Height, 8,
(int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB (),
CGImageAlphaInfo.PremultipliedFirst)) {
// draw our coordinates for reference
DrawCoordinateSpace (context);
// draw our flag
DrawFlag (context);
// add a label
DrawCenteredTextAtPoint (context, 384, 700, "Stars and Stripes", 60);
// output the drawing to the view
imageView.Image = UIImage.FromImage (context.ToImage ());
}
}
示例9: CreateImage
private UIImage CreateImage (NSString title, nfloat scale)
{
var titleAttrs = new UIStringAttributes () {
Font = UIFont.FromName ("HelveticaNeue", 13f),
ForegroundColor = Color.Gray,
};
var titleBounds = new CGRect (
new CGPoint (0, 0),
title.GetSizeUsingAttributes (titleAttrs)
);
var image = Image.TagBackground;
var imageBounds = new CGRect (
0, 0,
(float)Math.Ceiling (titleBounds.Width) + image.CapInsets.Left + image.CapInsets.Right + 4f,
(float)Math.Ceiling (titleBounds.Height) + image.CapInsets.Top + image.CapInsets.Bottom
);
titleBounds.X = image.CapInsets.Left + 2f;
titleBounds.Y = image.CapInsets.Top;
UIGraphics.BeginImageContextWithOptions (imageBounds.Size, false, scale);
try {
image.Draw (imageBounds);
title.DrawString (titleBounds, titleAttrs);
return UIGraphics.GetImageFromCurrentImageContext ();
} finally {
UIGraphics.EndImageContext ();
}
}
示例10: FinishedLaunching
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
// Two disjoint rects
var r1 = new CGRect (50, 50, 10, 10);
var r2 = new CGRect (100, 100, 10, 10);
// This condradicts with Apple's doc – https://developer.apple.com/reference/coregraphics/cgrectnull
// The null rectangle. This is the rectangle returned when, for example, you intersect two disjoint rectangles.
// Note that the null rectangle is not the same as the zero rectangle.
// For example, the union of a rectangle with the null rectangle is the original rectangle (that is, the null rectangle contributes nothing).
var tmp = r1;
tmp.Intersect (r2); // this is mutable method
Console.WriteLine (tmp.IsNull ()); // Expected true, but result is false
tmp = CGRectIntersection (r1, r2);
Console.WriteLine (tmp.IsNull ()); // Expected true, actual true
// This should be CGRectNull
var rectNull = new CGRect (nfloat.PositiveInfinity, nfloat.PositiveInfinity, 0, 0);
Console.WriteLine (rectNull.IsNull ()); // Expected true, actual true
// CGRectEmpty and CGRectNull are different
var union1 = r1.UnionWith (CGRect.Empty); // new rect {0, 0, 60, 60}
Console.WriteLine (union1);
var union2 = r1.UnionWith (rectNull); // r1
Console.WriteLine (union2);
return true;
}
示例11: GridCollectionView
/// <summary>
/// Initializes a new instance of the <see cref="GridCollectionView"/> class.
/// </summary>
/// <param name="frm">The FRM.</param>
public GridCollectionView(CGRect frm)
: base(frm, new UICollectionViewFlowLayout())
{
AutoresizingMask = UIViewAutoresizing.All;
ContentMode = UIViewContentMode.ScaleToFill;
RegisterClassForCell(typeof(GridViewCell), new NSString (GridViewCell.Key));
}
示例12: TouchDrawView
public TouchDrawView(CGRect rect)
: base(rect)
{
linesInProcess = new Dictionary<string, Line>();
this.BackgroundColor = UIColor.White;
this.MultipleTouchEnabled = true;
UITapGestureRecognizer tapRecognizer = new UITapGestureRecognizer(tap);
this.AddGestureRecognizer(tapRecognizer);
UITapGestureRecognizer dbltapRecognizer = new UITapGestureRecognizer(dblTap);
dbltapRecognizer.NumberOfTapsRequired = 2;
this.AddGestureRecognizer(dbltapRecognizer);
UILongPressGestureRecognizer pressRecognizer = new UILongPressGestureRecognizer(longPress);
this.AddGestureRecognizer(pressRecognizer);
moveRecognizer = new UIPanGestureRecognizer(moveLine);
moveRecognizer.WeakDelegate = this;
moveRecognizer.CancelsTouchesInView = false;
this.AddGestureRecognizer(moveRecognizer);
UISwipeGestureRecognizer swipeRecognizer = new UISwipeGestureRecognizer(swipe);
swipeRecognizer.Direction = UISwipeGestureRecognizerDirection.Up;
swipeRecognizer.NumberOfTouchesRequired = 3;
this.AddGestureRecognizer(swipeRecognizer);
selectedColor = UIColor.Red;
}
示例13: ViewDidLayoutSubviews
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews ();
UIView[] subviews = View.Subviews.Where (v => v != NavigationBar).ToArray ();
var toolBarViews = subviews.Where (v => v is UIToolbar).ToArray ();
var otherViews = subviews.Where (v => !(v is UIToolbar)).ToArray ();
nfloat toolbarHeight = 0;
foreach (var uIView in toolBarViews) {
uIView.SizeToFit ();
uIView.Frame = new CGRect {
X = 0,
Y = View.Bounds.Height - uIView.Frame.Height,
Width = View.Bounds.Width,
Height = uIView.Frame.Height,
};
var thisToolbarHeight = uIView.Frame.Height;
if (toolbarHeight < thisToolbarHeight) {
toolbarHeight = thisToolbarHeight;
}
}
var othersHeight = View.Bounds.Height - toolbarHeight;
var othersFrame = new CGRect (View.Bounds.X, View.Bounds.Y, View.Bounds.Width, othersHeight);
foreach (var uIView in otherViews) {
uIView.Frame = othersFrame;
}
}
示例14: Create
public static BaseItemView Create (CGRect frame, NodeViewController nodeViewController, TreeNode node, string filePath, UIColor kleur)
{
var view = BaseItemView.Create(frame, nodeViewController, node, kleur);
UIWebView webView = new UIWebView();
string extension = Path.GetExtension (filePath);
if (extension == ".odt") {
string viewerPath = NSBundle.MainBundle.PathForResource ("over/viewer/index", "html");
Uri fromUri = new Uri(viewerPath);
Uri toUri = new Uri(filePath);
Uri relativeUri = fromUri.MakeRelativeUri(toUri);
String relativePath = Uri.UnescapeDataString(relativeUri.ToString());
NSUrl finalUrl = new NSUrl ("#" + relativePath.Replace(" ", "%20"), new NSUrl(viewerPath, false));
webView.LoadRequest(new NSUrlRequest(finalUrl));
webView.ScalesPageToFit = true;
view.ContentView = webView;
return view;
} else {
NSUrl finalUrl = new NSUrl (filePath, false);
webView.LoadRequest(new NSUrlRequest(finalUrl));
webView.ScalesPageToFit = true;
view.ContentView = webView;
return view;
}
}
示例15: AddText
/// <summary>
/// Adds the text.
/// </summary>
/// <param name="image">The image.</param>
/// <param name="text">The text.</param>
/// <param name="point">The point.</param>
/// <param name="font">The font.</param>
/// <param name="color">The color.</param>
/// <param name="alignment">The alignment.</param>
/// <returns>UIImage.</returns>
public static UIImage AddText(
this UIImage image,
string text,
CGPoint point,
UIFont font,
UIColor color,
UITextAlignment alignment = UITextAlignment.Left)
{
//var labelRect = new RectangleF(point, new SizeF(image.Size.Width - point.X, image.Size.Height - point.Y));
var h = text.StringHeight(font, image.Size.Width);
var labelRect = new CGRect(point, new CGSize(image.Size.Width - point.X, h));
var label = new UILabel(labelRect)
{
Font = font,
Text = text,
TextColor = color,
TextAlignment = alignment,
BackgroundColor = UIColor.Clear
};
var labelImage = label.ToNativeImage();
using (var context = image.Size.ToBitmapContext())
{
var rect = new CGRect(new CGPoint(0, 0), image.Size);
context.DrawImage(rect, image.CGImage);
context.DrawImage(labelRect, labelImage.CGImage);
context.StrokePath();
return UIImage.FromImage(context.ToImage());
}
}