本文整理汇总了C#中CALayer.AddSublayer方法的典型用法代码示例。如果您正苦于以下问题:C# CALayer.AddSublayer方法的具体用法?C# CALayer.AddSublayer怎么用?C# CALayer.AddSublayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CALayer
的用法示例。
在下文中一共展示了CALayer.AddSublayer方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupLayers
private CALayer SetupLayers()
{
backgroundLayer = SetupBackgroundLayer ();
backgroundLayer.AddSublayer (SetupClockFaceLayer ());
backgroundLayer.AddSublayer (SetupBorderLayer ());
backgroundLayer.AddSublayer (SetupGlossyLayer ());
return backgroundLayer;
}
示例2: Draw
public static void Draw(CALayer target, IViewport viewport, IStyle style, IFeature feature)
{
const string styleKey = "laag";
if(feature[styleKey] == null) feature[styleKey] = ToiOSBitmap(feature.Geometry);
var bitmap = (UIImage)feature [styleKey];
var dest = WorldToScreen(viewport, feature.Geometry.GetBoundingBox());
dest = new BoundingBox(
dest.MinX,
dest.MinY,
dest.MaxX,
dest.MaxY);
var destination = RoundToPixel(dest);
var tile = new CALayer
{
Frame = destination,
Contents = bitmap.CGImage,
};
target.AddSublayer(tile);
}
示例3: AwakeFromNib
public override void AwakeFromNib()
{
base.AwakeFromNib();
View.Layer = new CALayer();
View.WantsLayer = true;
textContainer = new CALayer();
textContainer.AnchorPoint = CGPoint.Empty;
textContainer.Position = new CGPoint(10, 10);
textContainer.ZPosition = 100;
textContainer.BackgroundColor = NSColor.Black.CGColor;
textContainer.BorderColor = NSColor.White.CGColor;
textContainer.BorderWidth = 2;
textContainer.CornerRadius = 15;
textContainer.ShadowOpacity = 0.5f;
View.Layer.AddSublayer(textContainer);
textLayer = new CATextLayer();
textLayer.AnchorPoint = CGPoint.Empty;
textLayer.Position = new CGPoint(10, 6);
textLayer.ZPosition = 100;
textLayer.FontSize = 24;
textLayer.ForegroundColor = NSColor.White.CGColor;
textContainer.AddSublayer(textLayer);
// Rely on setText: to set the above layers' bounds: [self setText:@"Loading..."];
SetText("Loading...", textLayer);
var dirs = NSSearchPath.GetDirectories(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.Local);
foreach (string dir in dirs) {
Console.WriteLine("Dir: {0}", dir);
}
string libDir = dirs[0];
string desktopPicturesDir = Path.Combine(libDir, "Desktop Pictures");
Console.WriteLine("DP Dir: {0}", desktopPicturesDir);
// Launch loading of images on background thread
Task.Run(async () => {
await AddImagesFromFolderUrlAsync(desktopPicturesDir);
});
repositionButton.Layer.ZPosition = 100;
durationTextField.Layer.ZPosition = 100;
lastWindowSize = Window.Frame.Size;
Window.DidResize += (sender, e) => {
if (Math.Abs(lastWindowSize.Width - Window.Frame.Width) > 25 || Math.Abs(lastWindowSize.Height - Window.Frame.Height) > 25) {
windowIsResizing = true;
repositionImages(repositionButton);
lastWindowSize = Window.Frame.Size;
windowIsResizing = false;
}
};
}
示例4: Draw
public static void Draw(CALayer target, IViewport viewport, IStyle style, IFeature feature)
{
var lineString = ((LineString) feature.Geometry).Vertices;
var path = ((LineString) feature.Geometry).Vertices.ToUIKit(viewport);
var vectorStyle = (style as VectorStyle) ?? new VectorStyle();
var shape = new CAShapeLayer
{
StrokeColor = vectorStyle.Line.Color.ToCG(),
LineWidth = (float)vectorStyle.Line.Width,
Path = path.CGPath
};
target.AddSublayer (shape);
}
示例5: RenderPoint
public static void RenderPoint(CALayer target, CGPoint point, IStyle style, IViewport viewport, IFeature feature)
{
CALayer symbol;
float rotation = 0;
float scale = 1;
if (style is SymbolStyle)
{
var symbolStyle = style as SymbolStyle;
rotation = (float)symbolStyle.SymbolRotation;
scale = (float)symbolStyle.SymbolScale;
if (symbolStyle.BitmapId < 0)
{
symbol = CreateSymbolFromVectorStyle(symbolStyle);
}
else
{
symbol = CreateSymbolFromBitmap(symbolStyle);
}
if (symbolStyle.Outline != null)
{
symbol.BorderColor = symbolStyle.Outline.Color.ToCG();
symbol.BorderWidth = (float)symbolStyle.Outline.Width;
}
}
else if (style is VectorStyle)
{
var vectorStyle = (VectorStyle)style;
symbol = CreateSymbolFromVectorStyle(vectorStyle);
}
else
{
symbol = CreateSymbolFromVectorStyle(new VectorStyle());
}
symbol.AffineTransform = CreateAffineTransform(rotation, viewport.WorldToScreen(point), scale);
target.AddSublayer(symbol);
}
示例6: LayoutSubviews
/// <summary>
/// Lays out the subviews for this view.
/// </summary>
public override void LayoutSubviews()
{
base.LayoutSubviews();
// Create the colors for our gradient.
UIColor transparent = UIColor.FromWhiteAlpha(1.0f, 0);
UIColor opaque = UIColor.FromWhiteAlpha(1.0f, 1.0f);
// Create a masklayer.
CALayer maskLayer = new CALayer() { Frame = this.Bounds };
CAGradientLayer gradientLayer = new CAGradientLayer()
{
Frame = new RectangleF(this.Bounds.X, 0, this.Bounds.Size.Width, this.Bounds.Size.Height),
Colors = new CGColor[] { transparent.CGColor, transparent.CGColor, opaque.CGColor, opaque.CGColor },
Locations = new NSNumber[] { 0.0f, 0.09f, 0.11f, 1.0f }
};
// Add the mask.
maskLayer.AddSublayer(gradientLayer);
this.Layer.Mask = maskLayer;
}
示例7: Draw
public static void Draw(CALayer target, IViewport viewport, IStyle style, IFeature feature)
{
var point = feature.Geometry as Geometries.Point;
var dest = viewport.WorldToScreen(point);
//var path = UIBezierPath.FromRect(new Rectangle((int)dest.X, (int)dest.Y, 20, 20));
var path = CGPath.FromRect(new CGRect((float)dest.X, (float)dest.Y, 20, 20), CGAffineTransform.MakeIdentity());
style = new VectorStyle();
if (!feature.RenderedGeometry.Keys.Contains(style))
{
feature.RenderedGeometry[style] = CreateRenderedPoint();
}
else
{
Console.WriteLine("test");
}
var renderedGeometry = (CAShapeLayer) feature.RenderedGeometry[style];
renderedGeometry.Path = path;
target.AddSublayer(renderedGeometry);
}
示例8: AwakeFromNib
public override void AwakeFromNib ()
{
Layer = new CALayer ();
Layer.AddSublayer (MovingLayer);
WantsLayer = true;
}
示例9: HypnosisView
public HypnosisView(CGRect frame)
{
Frame = frame;
BackgroundColor = UIColor.Clear;
circleColor = UIColor.LightGray;
// Create the new layer object
boxLayer = new CALayer();
// Give it a size
boxLayer.Bounds = new CGRect(0.0f, 0.0f, 85.0f, 85.0f);
// Give it a location
boxLayer.Position = new CGPoint(160.0f, 100.0f);
// Round the corners
boxLayer.CornerRadius = 20.0f;
// Set a shadow
UIColor shadowColor = UIColor.Blue;
boxLayer.ShadowColor = shadowColor.CGColor;
boxLayer.ShadowOffset = new CGSize(5.0f, 5.0f);
boxLayer.ShadowOpacity = 1.0f;
// Make half transparent red the background color for the layer
UIColor reddish = new UIColor(1.0f, 0.0f, 0.0f, 1.0f);
// Get a CGColor object with the same color values
CGColor cgReddish = reddish.CGColor;
boxLayer.BackgroundColor = cgReddish;
boxLayer.Opacity = 0.5f;
// Create a UIImage
UIImage layerImage = new UIImage("Hypno.png");
// Get the underlying CGimage
CGImage image = layerImage.CGImage;
// Put the CGImage on the layer
boxLayer.Contents = image;
// Inset the image a but on each side
boxLayer.ContentsRect = new CGRect(-0.1f, -0.1f, 1.2f, 1.2f);
// Let the image resize (without changing aspect ratio
// to fill the contentRct
boxLayer.ContentsGravity = CALayer.GravityResizeAspect;
//
// Boxlayers sublayer
// Create the new layer object
CALayer boxSublayer = new CALayer();
// Give it a size
boxSublayer.Bounds = new CGRect(0.0f, 0.0f, boxLayer.Bounds.Size.Width/2, boxLayer.Bounds.Size.Height/2);
// Give it a location
boxSublayer.Position = new CGPoint(boxLayer.Bounds.Size.Width/2, boxLayer.Bounds.Size.Height/2);
// Round the corners
boxSublayer.CornerRadius = 10.0f;
// Make half transparent red the background color for the layer
UIColor greenish = new UIColor(0.0f, 1.0f, 0.0f, 0.5f);
// Get a CGColor object with the same color values
CGColor cgGreenish = greenish.CGColor;
boxSublayer.BackgroundColor = cgGreenish;
// Create a UIImage
UIImage subLayerImage = new UIImage("Map.png");
// Get the underlying CGimage
CGImage subImage = subLayerImage.CGImage;
// Put the CGImage on the layer
boxSublayer.Contents = subImage;
// Let the image resize (without changing aspect ratio
// to fill the contentRct
boxSublayer.ContentsGravity = CALayer.GravityResizeAspect;
// end boxlayers sublayer
//
// Make it a sublayer of the view's layer
boxLayer.AddSublayer(boxSublayer);
this.Layer.AddSublayer(boxLayer);
}
示例10: RenderLabelLayer
public static CALayer RenderLabelLayer(IViewport viewport, LabelLayer layer, List<IFeature> features)
{
var canvas = new CALayer();
canvas.Opacity = (float)layer.Opacity;
//todo: take into account the priority
var stackOffset = new Offset();
if (layer.Style != null)
{
var style = layer.Style;
foreach (var feature in features)
{
if (style is IThemeStyle) style = (style as IThemeStyle).GetStyle(feature);
if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.Resolution) || (style.MaxVisible < viewport.Resolution)) continue;
if (!(style is LabelStyle)) throw new Exception("Style of label is not a LabelStyle");
//var labelStyle = style as LabelStyle;
string labelText = layer.GetLabelText(feature);
var label = RenderLabel (feature.Geometry as Mapsui.Geometries.Point,
style as LabelStyle, feature, viewport, labelText);
canvas.AddSublayer(label);
}
}
return canvas;
}
示例11: PresentImage
//- (void)presentImage:(NSImage *)image;
void PresentImage(NSImage image, string filename)
{
int animationSpeed = 3;
CGRect superLayerBounds = View.Layer.Bounds;
CGPoint center = new CGPoint(superLayerBounds.GetMidX(), superLayerBounds.GetMidY());
CGRect imageBounds = new CGRect(0, 0, image.Size.Width, image.Size.Height);
nfloat X = (nfloat)random.Next((int)Math.Floor(imageBounds.Width/2), (int)Math.Floor(superLayerBounds.GetMaxX() - imageBounds.Width/2));//(superLayerBounds.GetMaxX() - imageBounds.Width/2) * random.NextDouble();
nfloat Y = (nfloat)random.Next((int)Math.Floor(imageBounds.Height/2), (int)Math.Floor(superLayerBounds.GetMaxY() - imageBounds.Height/2)); //(superLayerBounds.GetMaxY() - imageBounds.Height/2) * random.NextDouble();
CGPoint randomPoint = new CGPoint(X, Y);
CAMediaTimingFunction tf = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
// Animations for image layer
CABasicAnimation posAnim = CABasicAnimation.FromKeyPath("position");
posAnim.From = NSValue.FromCGPoint(center);
posAnim.Duration = animationSpeed;
posAnim.TimingFunction = tf;
CABasicAnimation bdsAnim = CABasicAnimation.FromKeyPath("bounds");
bdsAnim.From = NSValue.FromCGRect(CGRect.Empty);
bdsAnim.Duration = animationSpeed;
bdsAnim.TimingFunction = tf;
// Image layer
CALayer layer = new CALayer();
layer.Contents = image.CGImage;
layer.Position = center;
layer.ZPosition = random.Next(-100, 99);
layer.Actions = NSDictionary.FromObjectsAndKeys(new NSObject[]{posAnim, bdsAnim}, new NSObject[]{new NSString("position"), new NSString("bounds")});
// Animation for text layer
CATransform3D scale = CATransform3D.MakeScale(0.0f, 0.0f, 0.0f);
CABasicAnimation tScaleAnim = CABasicAnimation.FromKeyPath("transform");
tScaleAnim.From = NSValue.FromCATransform3D(scale);
tScaleAnim.Duration = animationSpeed;
tScaleAnim.TimingFunction = tf;
// text layer
CATextLayer fileNameLayer = new CATextLayer();
fileNameLayer.FontSize = 24;
fileNameLayer.ForegroundColor = NSColor.White.CGColor;
SetText(" " + filename + " ", fileNameLayer);
fileNameLayer.Transform = scale;
fileNameLayer.Position = CGPoint.Empty;
fileNameLayer.AnchorPoint = CGPoint.Empty;
fileNameLayer.ShadowColor = NSColor.Black.CGColor;
fileNameLayer.ShadowOffset = new CGSize(5, 5);
fileNameLayer.ShadowOpacity = 1.0f;
fileNameLayer.ShadowRadius = 0.0f;
fileNameLayer.BorderColor = NSColor.White.CGColor;
fileNameLayer.BorderWidth = 1.0f;
fileNameLayer.Actions = NSDictionary.FromObjectsAndKeys(new NSObject[]{tScaleAnim}, new NSObject[]{new NSString("transform")});
layer.AddSublayer(fileNameLayer);
View.Layer.AddSublayer(layer);
CATransaction.Begin();
layer.Position = randomPoint;
layer.Bounds = imageBounds;
fileNameLayer.Transform = CATransform3D.Identity;
CATransaction.Commit();
}
示例12: AwakeFromNib
public override void AwakeFromNib ()
{
// center our fire horizontally on the view and 15px from the bottom
var firePosition = new CGPoint (view.Bounds.Width / 2, 15);
rootLayer = new CALayer {
BackgroundColor = new CGColor (0, 0, 0)
};
fireEmitter = new CAEmitterLayer {
Position = firePosition,
Mode = CAEmitterLayer.ModeOutline,
Shape = CAEmitterLayer.ShapeLine,
RenderMode = CAEmitterLayer.RenderAdditive,
Size = CGSize.Empty,
Cells = new [] {
new CAEmitterCell {
Name = "fire", // name the cell so that it can be animated later using keypaths
EmissionLongitude = (float)Math.PI,
BirthRate = 0,
Velocity = 80,
VelocityRange = 30,
EmissionRange = 1.1f,
AccelerationY = 200,
ScaleSpeed = 0.3f,
Color = new CGColor (0.8f, 0.4f, 0.2f, 0.10f),
Contents = NSImage.ImageNamed ("fire.png").CGImage
}
}
};
smokeEmitter = new CAEmitterLayer {
Position = firePosition,
Mode = CAEmitterLayer.ModePoints,
Cells = new [] {
new CAEmitterCell {
Name = "smoke", // name the cell so that it can be animated later using keypaths
BirthRate = 11,
EmissionLongitude = (float)Math.PI / 2,
LifeTime = 0,
Velocity = 40,
VelocityRange = 20,
EmissionRange = (float)Math.PI / 4,
Spin = 1,
SpinRange = 6,
AccelerationY = 160,
Scale = 0.1f,
AlphaSpeed = -0.12f,
ScaleSpeed = 0.7f,
Contents = NSImage.ImageNamed ("smoke.png").CGImage
}
}
};
rootLayer.AddSublayer (smokeEmitter);
rootLayer.AddSublayer (fireEmitter);
view.Layer = rootLayer;
view.WantsLayer = true;
// Set the fire simulation to reflect the intial slider postion
slidersChanged (this);
// Force the view to update
view.NeedsDisplay = true;
}