public ImagePanScrollBarView(RectangleF frame, UIEdgeInsets edgeInsets) : base(frame) { var scrollbarPath = UIBezierPath.Create (); scrollbarPath.MoveTo (new PointF (edgeInsets.Left, Bounds.Height - edgeInsets.Bottom)); scrollbarPath.AddLineTo (new PointF (Bounds.Width - edgeInsets.Right, Bounds.Height - edgeInsets.Bottom)); var backgroundLayer = new CAShapeLayer () { Path = scrollbarPath.CGPath, LineWidth = 1, StrokeColor = UIColor.White.ColorWithAlpha (.1f).CGColor, FillColor = UIColor.Clear.CGColor }; scrollbarLayer = new CAShapeLayer () { Path = scrollbarPath.CGPath, LineWidth = 1, StrokeColor = UIColor.White.CGColor, FillColor = UIColor.Clear.CGColor, Actions = new NSDictionary ("strokeStart", NSNull.Null, "strokeEnd", NSNull.Null) }; Layer.AddSublayer (backgroundLayer); Layer.AddSublayer (scrollbarLayer); }
CAShapeLayer GetMaskShape (ViewMaskerType maskType, Xamarin.Forms.Size size) { var layer = new CAShapeLayer (); layer.FillColor = UIColor.White.CGColor; layer.StrokeColor = UIColor.White.CGColor; layer.LineWidth = 0; UIBezierPath path = null; var bounds = new CGRect (0, 0, size.Width, size.Height); switch (maskType) { case ViewMaskerType.Circle: path = UIBezierPath.FromRoundedRect (bounds, (nfloat)Math.Max (size.Width, size.Height)); break; case ViewMaskerType.Triangle: var point1 = new CGPoint (0, size.Height); var point2 = new CGPoint (size.Width, size.Height); var point3 = new CGPoint (size.Width / 2, 0); path = new UIBezierPath (); path.MoveTo (point1); path.AddLineTo (point2); path.AddLineTo (point3); path.AddLineTo (point1); path.ClosePath (); path.Fill (); break; case ViewMaskerType.Square: var smallRectangle = UIBezierPath.FromRect (bounds.Inset (50, 50)); path = UIBezierPath.FromRoundedRect (bounds, 20); break; default: throw new ArgumentOutOfRangeException (); } layer.Path = path.CGPath; return layer; }
public override void LayoutSubviews() { base.LayoutSubviews(); var rectShape = new CAShapeLayer(); rectShape.Bounds = Control.Bounds; rectShape.Position = Control.Center; UIRectCorner rectCorner; switch (_cornerSide) { case CornerSide.LeftSide: rectCorner = UIRectCorner.BottomLeft | UIRectCorner.TopLeft; break; case CornerSide.RightSide: rectCorner = UIRectCorner.BottomRight | UIRectCorner.TopRight; break; default : rectCorner = UIRectCorner.AllCorners; break; } rectShape.Path = UIBezierPath.FromRoundedRect(Control.Bounds, rectCorner, new CGSize(_cornerRadius, _cornerRadius)).CGPath; Control.Layer.Mask = rectShape; Control.Layer.MasksToBounds = true; CreateAngleForPicker(); }
private void Initialize() { SetDefaultTheme(); TintColor = UIColor.White; Layer.BackgroundColor = UIColor.Clear.CGColor; float radius = Bounds.Width / 2; _layerCircle = new CAShapeLayer(); _layerCircle.AllowsEdgeAntialiasing = true; _layerCircle.Bounds = Bounds; _layerCircle.Path = UIBezierPath.FromRoundedRect(new RectangleF(0, 0, 2f * radius, 2f * radius), radius).CGPath; _layerCircle.Position = new PointF(Bounds.Width / 2, Bounds.Height / 2); _layerCircle.FillColor = FillColor.CGColor; _layerCircle.StrokeColor = StrokeColor.CGColor; _layerCircle.LineWidth = 1f; Layer.AddSublayer(_layerCircle); GlyphImageView = new UIImageView(); GlyphImageView.BackgroundColor = UIColor.Clear; GlyphImageView.Layer.AnchorPoint = new PointF(0.5f, 0.5f); GlyphImageView.Frame = new RectangleF((Frame.Width - 50) / 2, (Frame.Height - 50) / 2, 50, 50); GlyphImageView.Alpha = GlyphAlpha; TitleLabel.Alpha = 0; TitleLabel.Hidden = true; TitleLabel.Text = string.Empty; AddSubview(GlyphImageView); }
private static CALayer CreateSymbolFromVectorStyle(VectorStyle style) { const int defaultWidth = 32; const int defaultHeight = 32; var symbol = new CAShapeLayer(); if (style.Fill != null && style.Fill.Color != null) { symbol.FillColor = style.Fill.Color.ToCG(); } else { symbol.BackgroundColor = new CGColor(0, 0, 0, 0); } if (style.Outline != null) { symbol.LineWidth = (float)style.Outline.Width; symbol.StrokeColor = style.Outline.Color.ToCG(); } var frame = new CGRect(-defaultWidth * 0.5f, -defaultHeight * 0.5f, defaultWidth, defaultHeight); symbol.Path = UIBezierPath.FromRoundedRect((CGRect)frame, (nfloat)frame.Width / 2).CGPath; return symbol; }
public override void AnimateTransition (IUIViewControllerContextTransitioning transitionContext) { _transitionContext = transitionContext; var containerView = transitionContext.ContainerView; FlashCardViewController toViewController; UIViewController fromViewController; if (Presenting) { fromViewController = transitionContext.GetViewControllerForKey (UITransitionContext.FromViewControllerKey) as UIViewController; toViewController = transitionContext.GetViewControllerForKey (UITransitionContext.ToViewControllerKey) as FlashCardViewController; } else { toViewController = transitionContext.GetViewControllerForKey (UITransitionContext.FromViewControllerKey) as FlashCardViewController; fromViewController = transitionContext.GetViewControllerForKey (UITransitionContext.ToViewControllerKey) as UIViewController; } if(Presenting) containerView.AddSubview(toViewController.View); var originRect = toViewController.SourceFrame; var circleRect = new CGRect (originRect.GetMidX(), originRect.GetMidY(), 10, 10); var circleMaskPathInitial = UIBezierPath.FromOval(circleRect); //(ovalInRect: button.frame); var extremePoint = new CGPoint(circleRect.X - toViewController.View.Bounds.Width, circleRect.Y - toViewController.View.Bounds.Height ); //CGRect.GetHeight (toViewController.view.bounds)); var radius = (float)Math.Sqrt((extremePoint.X * extremePoint.X) + (extremePoint.Y * extremePoint.Y)); var largeCircleRect = circleRect.Inset (-radius, -radius); var circleMaskPathFinal = UIBezierPath.FromOval (largeCircleRect); CGPath fromPath; CGPath toPath; if (Presenting) { fromPath = circleMaskPathInitial.CGPath; toPath = circleMaskPathFinal.CGPath; } else { var path = new CGPath (); fromPath = circleMaskPathFinal.CGPath; toPath = circleMaskPathInitial.CGPath; } var maskLayer = new CAShapeLayer(); maskLayer.Path = fromPath; if (Presenting) { toViewController.View.Layer.Mask = maskLayer; } else { toViewController.View.Layer.Mask = maskLayer; } var maskLayerAnimation = CABasicAnimation.FromKeyPath("path"); maskLayerAnimation.From = ObjCRuntime.Runtime.GetNSObject(fromPath.Handle); maskLayerAnimation.To = ObjCRuntime.Runtime.GetNSObject(toPath.Handle); maskLayerAnimation.Duration = this.TransitionDuration(transitionContext); _animDoneDelegate = new AnimDoneDelegate (transitionContext); maskLayerAnimation.Delegate = _animDoneDelegate; maskLayer.AddAnimation(maskLayerAnimation, "path"); }
public void Start () { waveBoundaryPath = new UIBezierPath (); waveLayer = new CAShapeLayer (); waveLayer.FillColor = new CGColor (0, 0, 0, 1); Layer.AddSublayer (waveLayer); waveDisplaylink = CADisplayLink.Create (() => GetCurrentWave (waveDisplaylink)); waveDisplaylink.AddToRunLoop (NSRunLoop.Main, NSRunLoop.NSDefaultRunLoopMode); }
private void setLayerCustom (UIView view) { UIBezierPath maskPath = UIBezierPath.FromRoundedRect ( view.Bounds, (UIRectCorner.BottomRight | UIRectCorner.BottomLeft), new CGSize(6.0f, 6.0f)); CAShapeLayer maskLayer = new CAShapeLayer (); maskLayer.Frame = view.Bounds; maskLayer.Path = maskPath.CGPath; view.Layer.Mask = maskLayer; }
/// <summary> /// Updates the layer's mask. On iOS there are no springs/struts (no auto resizing) on CALayers. Therefore the mask has to be adjusted whenever the /// UIView's properties are changed. /// </summary> /// </summary> private void UpdateMask() { // Add a layer that holds the rounded corners. UIBezierPath oMaskPath = UIBezierPath.FromRoundedRect (this.Bounds, this.eRoundedCorners, new SizeF (this.fCornerRadius, this.fCornerRadius)); CAShapeLayer oMaskLayer = new CAShapeLayer (); oMaskLayer.Frame = this.Bounds; oMaskLayer.Path = oMaskPath.CGPath; // Set the newly created shape layer as the mask for the image view's layer this.Layer.Mask = oMaskLayer; }
public override void Reset() { if (ListOfView.Count > 0) { ListOfView.Clear(); } if (_ds != null) { _ds = null; _node = null; _backgrundLayer = null; } }
public UISingleDayView() { _title = new UILabel() { Font = UIFont.PreferredBody }; this.Add(_title); _buttonExpand = new UIButton(UIButtonType.System); _buttonExpand.SetImage(UIImage.FromBundle("ToolbarDown").ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate), UIControlState.Normal); nfloat radians180 = unchecked ((nfloat)Math.PI); // 180 degrees is exactly PI in radians _buttonExpand.Transform = CGAffineTransform.MakeRotation(radians180); _buttonExpand.TouchUpInside += _buttonExpand_TouchUpInside; this.Add(_buttonExpand); _nothingDueText = new UILabel() { Font = UIFont.PreferredBody, Text = PowerPlannerResources.GetString("String_NothingDue"), TextAlignment = UITextAlignment.Center, TextColor = UIColor.LightGray }; this.Add(_nothingDueText); _line = new CAShapeLayer() { FillColor = UIColor.LightGray.CGColor }; this.Layer.AddSublayer(_line); _items = new UITableView() { SeparatorInset = UIEdgeInsets.Zero }; if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { // Stretch to full width even on iPad _items.CellLayoutMarginsFollowReadableWidth = false; } _scheduleSnapshot = new UIDayScheduleSnapshot(); _scheduleSnapshot.OnRequestViewClass += new WeakEventHandler <ViewItemClass>(_scheduleSnapshot_OnRequestViewClass).Handler; _items.TableFooterView = _scheduleSnapshot; this.Add(_items); MainScreenViewController.ListenToTabBarHeightChanged(ref _tabBarHeightListener, delegate { _items.ContentInset = new UIEdgeInsets(0, 0, MainScreenViewController.TAB_BAR_HEIGHT, 0); }); }
public override void Draw(CoreGraphics.CGRect rect) { base.Draw(rect); this.LayoutIfNeeded(); var control = (RoundedCornerView)Element; UIRectCorner uIRectCorner = 0; if (control != null) { if (control.TopLeft) { uIRectCorner |= UIRectCorner.TopLeft; } if (control.TopRight) { uIRectCorner |= UIRectCorner.TopRight; } if (control.BottomLeft) { uIRectCorner |= UIRectCorner.BottomRight; } if (control.BottomRight) { uIRectCorner |= UIRectCorner.BottomLeft; } if (!control.BottomLeft && !control.BottomRight && !control.TopLeft && !control.TopRight) { uIRectCorner = UIRectCorner.AllCorners; } nfloat radius = control.CornerRadius; var maskingShapeLayer = new CAShapeLayer { Path = UIBezierPath.FromRoundedRect(Bounds, uIRectCorner, new CGSize(radius, radius)).CGPath }; Layer.Mask = maskingShapeLayer; this.ClipsToBounds = true; this.Layer.MasksToBounds = true; this.Layer.BorderWidth = control.BorderWidth; if (control.BorderWidth > 0) { control.Padding = new Thickness(control.BorderWidth); this.Layer.BorderColor = control.BorderColor.ToCGColor(); } } }
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); }
private void UpdateMask() { // Add a layer that holds the rounded corners. UIBezierPath maskPath = UIBezierPath.FromRoundedRect(this.Bounds, roundedCorners, new SizeF(cornerRadius, cornerRadius)); var maskLayer = new CAShapeLayer(); maskLayer.Frame = this.Bounds; maskLayer.Path = maskPath.CGPath; // Set the newly created shape layer as the mask for the image view's layer this.Layer.Mask = maskLayer; }
private void Setup(PancakeView pancake) { // Create the border layer if (pancake.BorderThickness > 0) { if (_borderLayer == null) { _borderLayer = new CAShapeLayer(); } // Set the border color to clear if it's not set. if (pancake.BorderColor == Xamarin.Forms.Color.Default) { _borderLayer.StrokeColor = UIColor.Clear.CGColor; } else { _borderLayer.StrokeColor = pancake.BorderColor.ToCGColor(); } _borderLayer.FillColor = null; _borderLayer.LineWidth = pancake.BorderThickness * 2; // There's no border layer yet, insert it. if (Layer.Sublayers == null || (Layer.Sublayers != null && !Layer.Sublayers.Any(x => x.GetType() == typeof(CAShapeLayer)))) { Layer.InsertSublayer(_borderLayer, 0); } } if (pancake.HasShadow) { // TODO: Ideally we want to extract these to shadows. // However, we're very limited when it comes to shadows on Droid :( Layer.ShadowRadius = 10; Layer.ShadowColor = UIColor.Black.CGColor; Layer.ShadowOpacity = 0.4f; Layer.ShadowOffset = new SizeF(); Layer.MasksToBounds = false; } else { Layer.ShadowOpacity = 0; Layer.MasksToBounds = true; } // Set the rasterization for performance optimization. Layer.RasterizationScale = UIScreen.MainScreen.Scale; Layer.ShouldRasterize = true; }
public override void ViewDidLoad() { LocationEnabled = true; base.ViewDidLoad(); //adds a stationary circle around phone CAShapeLayer first = new CAShapeLayer(); first.Bounds = new CGRect(0, 0, PhoneImageView.Frame.Width, PhoneImageView.Frame.Height); first.Position = new CGPoint(PhoneImageView.Frame.Width / 2, PhoneImageView.Frame.Height / 2); first.Path = UIBezierPath.FromOval(PhoneImageView.Bounds).CGPath; first.StrokeColor = UIColor.White.CGColor; first.LineWidth = (nfloat)1; first.FillColor = UIColor.Clear.CGColor; PhoneImageView.Layer.AddSublayer(first); //Wire up events DemoCardView = new UIView(); DemoCardView.BackgroundColor = UIColor.Clear; DemoCardSuperviewHeightConstraint.Constant = CardViewController.GetCalculatedHeight(); DemoCardSuperview.AddSubview(DemoCardView); DemoCardSuperview.SetNeedsLayout(); DemoCardSuperview.LayoutIfNeeded(); DemoCardSuperview.BackgroundColor = UIColor.Clear; StatusButton.Hidden = true; StatusButton.TitleLabel.TextAlignment = UITextAlignment.Center; StatusButton.TitleLabel.LineBreakMode = UILineBreakMode.WordWrap; StatusButton.TitleLabel.Lines = 2; RightArrowImageView.Transform = CGAffineTransform.MakeScale(-1, 1); HideCardViews(true); //clear notifications var persistantStorageService = ServiceLocator.Instance.Resolve <IPersistantStorage>(); persistantStorageService.SetDiscoverNotificaionCount(0); if (IsSufficentPermissionGranted()) { var service = ServiceRunner.SharedInstance.FetchService <GeolocatorService>(); service.Start(); } StartLocationManager(); }
protected override void OnElementChanged(ElementChangedEventArgs <XFCircleProgress> e) { base.OnElementChanged(e); indicatorFontSize = Element.TextSize; backgroundCircle = new CAShapeLayer(); CreateBackgroundCircle(); CreateIndicatorCircle(); CreateIndicatorLabel(); }
private void DrawBar(CGPoint initialPoint, nfloat width, nfloat height, UIColor color) { var path = UIBezierPath.FromRoundedRect(new CGRect(initialPoint.X, initialPoint.Y - height, width, height), UIRectCorner.AllCorners, new CGSize(barsCornerRadius, barsCornerRadius)); var rectLayer = new CAShapeLayer { Path = path.CGPath, FillColor = color.CGColor, ContentsScale = UIScreen.MainScreen.Scale, AllowsEdgeAntialiasing = true }; Layer.AddSublayer(rectLayer); }
// Shared initialization code void Initialize() { WantsLayer = true; var center = new CGPoint(Frame.Width / 2, Frame.Height / 2); outerCircleLayer = new CAShapeLayer(); var path = new CGPath(); nfloat radis = (Frame.Width - 2) / 2; path.AddArc(center.X, center.Y, radis, 0, (float)(2 * Math.PI), true); outerCircleLayer.Path = path; outerCircleLayer.FillColor = NSColor.Clear.CGColor; outerCircleLayer.LineWidth = 1.0f; outerCircleLayer.StrokeColor = NSColor.White.CGColor; outerCircleLayer.StrokeStart = 0.0f; outerCircleLayer.StrokeEnd = 1.0f; Layer.AddSublayer(outerCircleLayer); progressLayer = new CAShapeLayer(); var progressPath = new CGPath(); float start = (float)(Math.PI / 2); float end = (float)(-3 * Math.PI / 2); radis = (Frame.Width - 6) / 2; progressPath.AddArc(center.X, center.Y, radis, start, end, true); progressLayer.Path = progressPath; progressLayer.FillColor = NSColor.Clear.CGColor; progressLayer.LineWidth = 3.0f; progressLayer.StrokeColor = NSColor.White.CGColor; progressLayer.StrokeStart = 0; progressLayer.StrokeEnd = 0.0f; Layer.AddSublayer(progressLayer); //Circle progress view center var centerRectLayer = new CAShapeLayer(); centerRectLayer.Bounds = new CGRect(0, 0, 8, 8); centerRectLayer.Position = center; centerRectLayer.FillColor = NSColor.White.CGColor; centerRectLayer.BackgroundColor = NSColor.White.CGColor; Layer.AddSublayer(centerRectLayer); }
// this is because of UIStackView is a non-drawing view, meaning that drawRect() is never called and its background color is ignored public override void LayoutSubviews() { base.LayoutSubviews(); var layer = new CAShapeLayer { Path = CGPath.FromRect(this.Bounds), FillColor = BackgroundColor?.CGColor }; //if (Layer.Sublayers == null) Layer.InsertSublayer(layer, 0); //else // Layer.ReplaceSublayer(Layer.Sublayers[0], layer); }
public void SetColorBinding(CAShapeLayer layer, string propertyPath) { SetBinding <byte[]>(propertyPath, colorArray => { if (colorArray != null) { layer.FillColor = BareUIHelper.ToCGColor(colorArray); } else { layer.FillColor = null; } }); }
CAShapeLayer CreateRingLayer(PointF center, float radius, float lineWidth, UIColor color) { var smoothedPath = CreateCirclePath(center, radius, 72); var slice = new CAShapeLayer(); slice.Frame = new RectangleF(center.X - radius, center.Y - radius, radius * 2, radius * 2); slice.FillColor = UIColor.Clear.CGColor; slice.StrokeColor = color.CGColor; slice.LineWidth = lineWidth; slice.LineCap = CAShapeLayer.JoinBevel; slice.LineJoin = CAShapeLayer.JoinBevel; slice.Path = smoothedPath.CGPath; return(slice); }
// this will draw background and circular border then it will cut the image to a circle inside the border and padding protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); // the control as it exists in the protable project formControl = (SelectImageButton)sender; // the click events form the forms control to be added to the end of the long click buttonevents = formControl.ClickEvents; // setting the colors for use in ther renderer outside of the property changed event iosBackgroundColor = formControl.BackgroundColor.ToCGColor(); iosBorderColor = formControl.BorderColor.ToCGColor(); iosBorderWidth = formControl.BorderWidth; iosHoldBackgroundColor = formControl.HoldBackgroundColor.ToCGColor(); iosHoldBorderColor = formControl.HoldBorderColor.ToCGColor(); iosHoldBorderWidth = formControl.HoldBorderWidth; // background Xamarin.Forms.Color bgcolor = formControl.BackgroundColor; Layer.BackgroundColor = bgcolor.ToCGColor(); // border Layer.BorderColor = formControl.BorderColor.ToCGColor(); Layer.BorderWidth = formControl.BorderWidth; Layer.CornerRadius = (float)formControl.Width / 2; // setup for a long press gesture UILongPressGestureRecognizer holdGesture = new UILongPressGestureRecognizer(holdPress); holdGesture.MinimumPressDuration = 0.0; this.AddGestureRecognizer(holdGesture); // this need to check that the control is actually loaded as it can call this method without the control present if (formControl != null) { // a top left and bottom right adjustment for the clipping border float TLborderControl = 0; float BRborderControl = formControl.BorderWidth; // a rectangle made usiing the bounds and borders of the control that we will use the cut an elipse with CGRect clipRect = new CGRect(); clipRect.X = (float)0 + TLborderControl; clipRect.Y = (float)0 + TLborderControl; clipRect.Width = (float)Element.Bounds.Width; clipRect.Height = (float)Element.Bounds.Height; CAShapeLayer clipShapeLayer = new CAShapeLayer(); CGPath clipPath = new CGPath(); clipPath.AddEllipseInRect(clipRect); clipShapeLayer.Path = clipPath; Layer.Mask = clipShapeLayer; } }
async void StartSearching() { if (Searching) { return; } Searching = true; ShouldStopSearching = false; if (!IsSufficentPermissionGranted()) { StatusButton.Hidden = false; StatusButton.SetTitle("Location Permission Necessary. \n Go to Settings", new UIControlState()); return; } shape = new CAShapeLayer(); shape.Bounds = new CGRect(0, 0, PhoneImageView.Frame.Width, PhoneImageView.Frame.Height); shape.Position = new CGPoint(PhoneImageView.Frame.Width / 2, PhoneImageView.Frame.Height / 2); shape.Path = UIBezierPath.FromOval(PhoneImageView.Bounds).CGPath; shape.StrokeColor = UIColor.White.CGColor; shape.LineWidth = (nfloat).5; shape.FillColor = UIColor.Clear.CGColor; PhoneImageView.Layer.AddSublayer(shape); CABasicAnimation grow = CABasicAnimation.FromKeyPath("transform.scale"); grow.From = NSObject.FromObject(20); grow.Duration = 2; grow.To = NSObject.FromObject(1); grow.FillMode = CAFillMode.Forwards; grow.RepeatCount = 10000; grow.RemovedOnCompletion = false; shape.AddAnimation(grow, "grow"); StatusButton.Hidden = false; StatusButton.SetTitle("Searching for people \n sharing nearby", new UIControlState()); while (!ShouldStopSearching && View.Window != null) { await Shared.GetNearbyTransactions(); StopSearchingIfCardsFound(); Console.WriteLine("GOT"); await Task.Delay(TimeSpan.FromSeconds(5)); Console.WriteLine("DONE"); } }
private void AddCornerRadius(PancakeView pancake) { if (pancake.CornerRadii.BottomLeft + pancake.CornerRadii.BottomRight + pancake.CornerRadii.TopLeft + pancake.CornerRadii.TopRight > 0) { var maskLayer = new CAShapeLayer { Frame = Bounds, Path = this.CreateCornerPath(pancake, false), }; Layer.Mask = maskLayer; Layer.MasksToBounds = true; } }
MDCInkView(NSCoder aDecoder) : base(aDecoder) { if (aDecoder.ContainsKey(MDCInkViewAnimationDelegateKey)) { AnimationDelegate = aDecoder.DecodeObject(MDCInkViewAnimationDelegateKey); } if (aDecoder.ContainsKey(MDCInkViewMaskLayerKey)) { MaskLayer = (CAShapeLayer)aDecoder.DecodeObject(MDCInkViewMaskLayerKey); MaskLayer.Delegate = this; } else { MaskLayer = new CAShapeLayer(); MaskLayer.Delegate = this; } if (aDecoder.ContainsKey(MDCInkViewUsesLegacyInkRippleKey)) { UsesLegacyInkRipple = aDecoder.DecodeBool(MDCInkViewUsesLegacyInkRippleKey); } else { UsesLegacyInkRipple = true; } if (aDecoder.ContainsKey(MDCInkViewInkStyleKey)) { InkStyle = (MDCInkStyle)aDecoder.DecodeInt(MDCInkViewInkStyleKey); } // The following are derived properties, but `layer` may not have been encoded if (aDecoder.ContainsKey(MDCInkViewUsesCustomInkCenterKey)) { UsesCustomInkCenter = aDecoder.DecodeBool(MDCInkViewUsesCustomInkCenterKey); } if (aDecoder.ContainsKey(MDCInkViewCustomInkCenterKey)) { CustomInkCenter = aDecoder.DecodeCGPoint(MDCInkViewCustomInkCenterKey); } if (aDecoder.ContainsKey(MDCInkViewMaxRippleRadiusKey)) { MaxRippleRadius = (nfloat)aDecoder.DecodeDouble(MDCInkViewMaxRippleRadiusKey); } if (aDecoder.ContainsKey(MDCInkViewInkColorKey)) { InkColor = (UIColor)aDecoder.DecodeObject(MDCInkViewInkColorKey); } }
public SelectionView(Terminal terminal, SelectionService selection, CGRect rect, CGRect typgographicalBounds) : base(rect) { this.terminal = terminal; this.selection = selection; selection.SelectionChanged += HandleSelectionChanged; rowHeight = (int)typgographicalBounds.Height; colWidth = typgographicalBounds.Width; rowDelta = typgographicalBounds.Y; WantsLayer = true; maskLayer = new CAShapeLayer(); Layer.Mask = maskLayer; }
public static Task <bool> BasicAnimationAsync( CAShapeLayer layer, string path, float duration, float from, float to, NSString timingFunction = null, string animationName = null ) { var nsFrom = new NSNumber(@from); var nsTo = new NSNumber(to); return(BasicAnimationAsync(layer, path, duration, nsFrom, nsTo, timingFunction, animationName)); }
public override void ViewDidLoad () { base.ViewDidLoad (); strategist = new GKMinMaxStrategist { MaxLookAheadDepth = 7, RandomSource = new GKARC4RandomSource () }; var columns = new CAShapeLayer[Board.Width][]; for (int column = 0; column < Board.Width; column++) columns [column] = new CAShapeLayer[Board.Height]; chipLayers = columns; ResetBoard (); }
public void DefineStyleForBottomCell() { // Round only bottom of view, this is to simulate round style in sections of TableView (group style of iOS 6) // Is necessary set the size manually because the constraints values haven't been setted yet // 40 it's the margin left and right of content view CGRect contentSize = new CGRect(0, 0, Frame.Size.Width - 40, Frame.Size.Height); UIBezierPath mPath = UIBezierPath.FromRoundedRect(contentSize, (UIRectCorner.BottomRight | UIRectCorner.BottomLeft), new CGSize(width: 5, height: 5)); CAShapeLayer maskLayer = new CAShapeLayer(); maskLayer.Frame = contentSize; maskLayer.Path = mPath.CGPath; containerView.Layer.Mask = maskLayer; }
public override void AwakeFromNib() { base.AwakeFromNib(); _ol_sortButton.Create(SortedViewPopupString.Name | SortedViewPopupString.Size); _ol_infoSwitcherView.WantsLayer = true; _backgrundLayer = new CAShapeLayer { CornerRadius = InfoSwitcherFloats.CornerRadius.AsResourceFloat(), BorderColor = InfoSwitcherColors.BorderColor.AsResourceCgColor(), BackgroundColor = SortedViewColor.HeaderColor.AsResourceCgColor(), BorderWidth = InfoSwitcherFloats.BorderWidth.AsResourceFloat() }; SortOutline(_ol_sortButton.CurrentSortByTitle); _ol_infoSwitcherView.Layer = _backgrundLayer; }
private void AddLineLayer(PointF start, PointF end) { var layer = new CAShapeLayer(); layer.Frame = Frame; layer.LineWidth = 0.5f; layer.StrokeColor = UIColor.Black.CGColor; var path = new UIBezierPath(); path.LineWidth = 0.5f; path.MoveTo(start); path.AddLineTo(end); layer.Path = path.CGPath; Layer.AddSublayer(layer); }
CAShapeLayer SetupProgressLayer() { _progressLayer = new CAShapeLayer { ShadowOpacity = ProgressButtonFloats.ProgressLayerShadowOpacity.AsResourceFloat(), FillColor = ProgressButtonColors.FillProgressColor.AsResourceCgColor() }; _progressLayer.Bind("path", _progressButtonLayer, "curPath", null); var checkMarkLayer = new CALayer(); checkMarkLayer.Frame = ProgressButtonRects.CheckMarkFrame.AsRect(); checkMarkLayer.Bind("contents", _progressButtonLayer, "curImage", null); _progressLayer.AddSublayer(checkMarkLayer); return(_progressLayer); }
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); }
private CAShapeLayer CreateCircleShapeLayer(float radius, float lineW) { var path = UIBezierPath.FromArc(CGPoint.Empty, radius - lineW / 2, 0, (nfloat)(2 * Math.PI), true); var layer = new CAShapeLayer(); layer.Path = path.CGPath; layer.LineWidth = lineW; layer.StrokeColor = itemColor.CGColor; layer.FillColor = UIColor.Clear.CGColor; return(layer); }
private CALayer createMinuteSegment(CGRect rect, CGColor color, nfloat distanceFromcenter, nfloat angle) { var layer = new CAShapeLayer(); var rotation = CGAffineTransform.MakeRotation(angle); var translation = CreateTranslationTransform(distanceFromcenter, angle); var transform = rotation * translation; var path = CGPath.FromRect(rect, transform); layer.Path = path; layer.FillColor = color; return(layer); }
void DrawQuadrangle(CGPoint p0, CGPoint p1, CGPoint p2, CGPoint p3, CALayer layer, RTRResultStabilityStatus progress) { var area = new CAShapeLayer(); var recognizedAreaPath = new UIBezierPath(); recognizedAreaPath.MoveTo(p0); recognizedAreaPath.AddLineTo(p1); recognizedAreaPath.AddLineTo(p2); recognizedAreaPath.AddLineTo(p3); recognizedAreaPath.ClosePath(); area.Path = recognizedAreaPath.CGPath; area.StrokeColor = ProgressColor(progress).CGColor; area.FillColor = UIColor.Clear.CGColor; layer.AddSublayer(area); }
private protected void Render(CGPath path, FillRule fillRule = FillRule.EvenOdd) { // Remove the old layer if any _shapeLayer?.RemoveFromSuperLayer(); // Well ... nothing to do ! if (path == null) { _shapeLayer = null; return; } _shapeLayer = CreateLayer(path, fillRule); Layer.AddSublayer(_shapeLayer); }
public ODRefreshControl(UIScrollView scrollView, UIActivityIndicatorView activity) : base(new RectangleF(0, -1 * (kTotalViewHeight + scrollView.ContentInset.Top), scrollView.Frame.Size.Width, kTotalViewHeight)) { this.scrollView = scrollView; this.originalContentInset = this.scrollView.ContentInset; this.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; this.scrollView.AddSubview(this); this.scrollView.AddObserver(this, new NSString("contentOffset"), NSKeyValueObservingOptions.New, IntPtr.Zero); this.scrollView.AddObserver(this, new NSString("contentInset"), NSKeyValueObservingOptions.New, IntPtr.Zero); if (activity == null) activity = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.Gray); this.activity = activity; this.activity.Center = new PointF((float)Math.Floor(this.Frame.Size.Width / 2), (float)Math.Floor(this.Frame.Size.Height / 2)); this.activity.AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin; this.activity.Alpha = 0; this.activity.StartAnimating(); this.AddSubview(this.activity); _refreshing = false; _canRefresh = true; _ignoreInset = false; _ignoreOffset = false; _didSetInset = false; _hasSectionHeaders = false; TintColor = UIColor.FromRGBA(155 / 255, 162 / 255, 172 / 255, 1.0f); _shapeLayer = new CAShapeLayer(); _shapeLayer.FillColor = TintColor.CGColor; _shapeLayer.StrokeColor = UIColor.DarkGray.ColorWithAlpha(0.5f).CGColor; _shapeLayer.LineWidth = 0.5f; _shapeLayer.ShadowColor = UIColor.Black.CGColor; _shapeLayer.ShadowOffset = new SizeF(0, 1); _shapeLayer.ShadowOpacity = 0.4f; _shapeLayer.ShadowRadius = 0.5f; this.Layer.AddSublayer(_shapeLayer); _arrowLayer = new CAShapeLayer(); _arrowLayer.StrokeColor = UIColor.DarkGray.ColorWithAlpha(0.5f).CGColor; _arrowLayer.LineWidth = 0.5f; _arrowLayer.FillColor = UIColor.White.CGColor; _shapeLayer.AddSublayer(_arrowLayer); _highlightLayer = new CAShapeLayer(); _highlightLayer.FillColor = UIColor.White.ColorWithAlpha(0.2f).CGColor; _shapeLayer.AddSublayer(_highlightLayer); }
public override void AnimateTransition(IUIViewControllerContextTransitioning transitionContext) { //1 _transitionContext = transitionContext; //2 var containerView = _transitionContext.ContainerView; var fromViewController = _transitionContext.GetViewControllerForKey(UITransitionContext.FromViewControllerKey) as OnboardingController; var toViewController = _transitionContext.GetViewControllerForKey(UITransitionContext.ToViewControllerKey) as ContainerController; var fromRect = fromViewController.NavigationRect; var toRect = new CGRect(-toViewController.View.Bounds.Width / 2, -toViewController.View.Bounds.Height / 2, toViewController.View.Bounds.Width * 2, toViewController.View.Bounds.Height * 2); //3 containerView.AddSubview(toViewController.View); //4 var circleMaskPathInitial = UIBezierPath.FromRoundedRect(fromRect, fromRect.Height / 2); var circleMaskPathFinal = UIBezierPath.FromRoundedRect(toRect, toRect.Height / 2); //5 var maskLayer = new CAShapeLayer(); maskLayer.Path = circleMaskPathFinal.CGPath; toViewController.View.Layer.Mask = maskLayer; //6 var maskLayerAnimation = CABasicAnimation.FromKeyPath("path"); maskLayerAnimation.SetFrom(circleMaskPathInitial.CGPath); maskLayerAnimation.SetTo(circleMaskPathFinal.CGPath); maskLayerAnimation.Duration = TransitionDuration(_transitionContext); maskLayerAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn); maskLayerAnimation.AnimationStopped += (object sender, CAAnimationStateEventArgs e) => { if (_transitionContext != null) { _transitionContext.CompleteTransition(!_transitionContext.TransitionWasCancelled); var controller = _transitionContext.GetViewControllerForKey(UITransitionContext.FromViewControllerKey); if (controller != null) { controller.View.Layer.Mask = null; } } }; maskLayer.AddAnimation(maskLayerAnimation, "path"); }
private void layoutSwitch() { if (TrackLayer == null) { TrackLayer = new CAShapeLayer(); } if (Button == null) { Button = new FabButton(); } nfloat w = 0; switch (SwitchSize) { case SwitchSize.Small: { w = 30; } break; case SwitchSize.Default: { w = 40; } break; case SwitchSize.Large: { w = 50; } break; } nfloat px = (this.Width() - w) / 2f; TrackLayer.Frame = new CGRect(px, (this.Height() - trackThickness) / 2f, w, trackThickness); TrackLayer.CornerRadius = NMath.Min(TrackLayer.Frame.Height, TrackLayer.Frame.Width) / 2f; Button.Frame = new CGRect(px, (this.Height() - buttonDiameter) / 2f, buttonDiameter, buttonDiameter); onPosition = this.Width() - px - buttonDiameter; offPosition = px; if (internalSwitchState == SwitchState.On) { Button.SetX(onPosition); } }
public override void LayoutSubviews() { base.LayoutSubviews(); // Adjust frame size to make it perfectly square Control.Layer.Frame = new CGRect(0, 0, elementHeight, elementHeight); Control.Superview.Bounds = Control.Layer.Frame; // Align Control in Superview //Control.VerticalAlignment = UIControlContentVerticalAlignment.Center; //Control.HorizontalAlignment = UIControlContentHorizontalAlignment.Center; // Make longer labels break on to multiple lines Control.TitleLabel.LineBreakMode = UILineBreakMode.WordWrap; Control.TitleLabel.TextAlignment = UITextAlignment.Center; // Provide some padding Control.TitleEdgeInsets = new UIEdgeInsets(5, 5, 5, 5); //Control.Layer.BackgroundColor = new CGColor(0.0f, 0.0f, 0.0f, 0.2f); if (circleLayer == null) { // Create inner circle circleLayer = new CAShapeLayer { Path = UIBezierPath.FromOval(new CGRect(3, 3, Control.Layer.Frame.Width - 6, Control.Layer.Frame.Height - 6)) .CGPath, FillColor = backgroundColor.CGColor, Position = new CGPoint(0, 0) }; Control.Layer.InsertSublayer(circleLayer, 0); // Creater static outer circle var staticCircleLayer = createOuterCircle(Control.Layer.Frame, backgroundColor); staticCircleLayer.Opacity = 1; Control.Layer.InsertSublayer(staticCircleLayer, 0); } }
public CustomLayerBasedView (CGRect rect) : base (rect) { WantsLayer = true; CAShapeLayer shapeLayer = new CAShapeLayer (); // Create a circle path CGPath path = new CGPath (); path.AddArc (rect.Width / 2, rect.Height / 2, (rect.Height / 2) - 10, (float)(-(Math.PI / 2)), (float)(3 * Math.PI / 2), false); shapeLayer.Path = path; shapeLayer.Position = new CGPoint (Bounds.Width / 2, Bounds.Height / 2); shapeLayer.FillColor = NSColor.LightGray.CGColor; shapeLayer.StrokeColor = NSColor.Blue.CGColor; shapeLayer.LineWidth = 2; Layer = shapeLayer; }
/// <summary> /// Redraws the progress circle. If the circle is already on the screen, it removes that one and creates a new one using the /// current properties of the view /// </summary> void RedrawCircle() { if (_progressCircle != null && _progressCircle.SuperLayer != null) { _progressCircle.RemoveFromSuperLayer (); } var centerPoint = new PointF (this.Bounds.Width / 2, this.Bounds.Height / 2); UIBezierPath circlePath = UIBezierPath.FromArc (centerPoint, this.Bounds.Width * .7f, (float)(-.5 * Math.PI), (float)(1.5 * Math.PI), true); _progressCircle = new CAShapeLayer (); _progressCircle.Path = circlePath.CGPath; _progressCircle.StrokeColor = UIColor.Green.CGColor; _progressCircle.FillColor = UIColor.Clear.CGColor; _progressCircle.LineWidth = 1.5f; _progressCircle.StrokeStart = 0f; _progressCircle.StrokeEnd = 0f; this.Layer.AddSublayer (_progressCircle); }
private static CALayer RenderImage(MultiPolygon multiPolygon, IStyle style, IViewport viewport) { var geom = new CAShapeLayer(); if (!(style is VectorStyle)) throw new ArgumentException("Style is not of type VectorStyle"); var vectorStyle = style as VectorStyle; float strokeAlpha = (float)vectorStyle.Outline.Color.A / 255; float fillAlpha = (float)vectorStyle.Fill.Color.A / 255; var strokeColor = new CGColor(new CGColor(vectorStyle.Outline.Color.R, vectorStyle.Outline.Color.G, vectorStyle.Outline.Color.B), strokeAlpha); var fillColor = new CGColor(new CGColor(vectorStyle.Fill.Color.R, vectorStyle.Fill.Color.G, vectorStyle.Fill.Color.B), fillAlpha); geom.StrokeColor = strokeColor; geom.FillColor = fillColor; geom.LineWidth = (float)vectorStyle.Outline.Width; var bbRect = GeometryRenderer.ConvertBoundingBox(multiPolygon.GetBoundingBox(), viewport); var offset = new CoreGraphics.CGPoint((int)bbRect.GetMinX(), (int)bbRect.GetMinY()); GeometryExtension.OffSet = offset; var path = multiPolygon.ToUIKit(viewport); var frame = new CGRect(0, 0, (int)((float)bbRect.GetMaxX() - (float)bbRect.GetMinX()), (int)((float)bbRect.GetMaxY() - (float)bbRect.GetMinY())); var size = frame.Size; geom.Path = path.CGPath; UIGraphics.BeginImageContext((CGSize)size); var context = UIGraphics.GetCurrentContext(); context.SetBlendMode(CGBlendMode.Multiply); geom.RenderInContext(context); var image = UIGraphics.GetImageFromCurrentImageContext(); var imageTile = new CALayer { Contents = image.CGImage, Frame = frame }; return imageTile; }
/// <summary> /// Replays the recorded gestures animated. /// </summary> /// <param name="coll">gesture collection to replay</param> /// <param name="duration">Duration in seconds.</param> /// <param name="color">Color.</param> public void Replay(float duration, UIColor color) { CAShapeLayer pathLayer = new CAShapeLayer (); pathLayer.Frame = this.PictureLoginView.DrawingAreaView.Bounds; pathLayer.GeometryFlipped = false; pathLayer.Path = this.PictureLoginView.DrawingAreaView.GesturePath; pathLayer.StrokeColor = color.CGColor; pathLayer.LineWidth = 5f; pathLayer.FillColor = UIColor.Clear.CGColor; CABasicAnimation pathAnimation = CABasicAnimation.FromKeyPath("strokeEnd"); pathAnimation.Duration = duration; pathAnimation.From = new NSNumber(0f); pathAnimation.To = new NSNumber(1f); pathAnimation.AnimationStopped += (object sender, CAAnimationStateEventArgs e) => { pathLayer.RemoveAnimation("strokeEndAnimation"); pathLayer.RemoveFromSuperLayer(); }; pathLayer.AddAnimation (pathAnimation, "strokeEndAnimation"); this.PictureLoginView.DrawingAreaView.Layer.AddSublayer (pathLayer); }
public void NullableProperties() { var sl = new CAShapeLayer (); Assert.NotNull (sl.FillColor, "FillColor"); sl.FillColor = null; Assert.Null (sl.Path, "Path"); sl.Path = null; Assert.Null (sl.LineDashPattern, "LineDashPattern"); sl.LineDashPattern = null; Assert.Null (sl.StrokeColor, "StrokeColor"); sl.StrokeColor = null; sl.FillColor = UIColor.Black.CGColor; Assert.NotNull (sl.FillColor, "FillColor"); sl.Path = new CGPath (); Assert.NotNull (sl.Path, "Path"); sl.LineDashPattern = new [] { new NSNumber (5), new NSNumber (10) }; Assert.NotNull (sl.LineDashPattern, "LineDashPattern"); sl.StrokeColor = UIColor.White.CGColor; Assert.NotNull (sl.StrokeColor, "StrokeColor"); }
public static CALayer RenderPolygonOnLayer(Polygon polygon, IStyle style, IViewport viewport) { var tile = new CAShapeLayer(); if (!(style is VectorStyle)) throw new ArgumentException("Style is not of type VectorStyle"); var vectorStyle = style as VectorStyle; var strokeAlpha = (float)vectorStyle.Outline.Color.A / 255; var fillAlpha = (float)vectorStyle.Fill.Color.A / 255; var strokeColor = new CGColor(new CGColor(vectorStyle.Outline.Color.R, vectorStyle.Outline.Color.G, vectorStyle.Outline.Color.B), strokeAlpha); var fillColor = new CGColor(new CGColor(vectorStyle.Fill.Color.R, vectorStyle.Fill.Color.G, vectorStyle.Fill.Color.B), fillAlpha); tile.StrokeColor = strokeColor; tile.FillColor = fillColor; tile.LineWidth = (float)vectorStyle.Outline.Width; tile.Path = polygon.ToUIKit(viewport).CGPath; return tile; }
public static CAShapeLayer RoundedMask(RectangleF frame, UIRectCorner corners, float radius) { UIBezierPath path = UIBezierPath.FromRoundedRect(frame, corners, new SizeF(radius, radius)); CAShapeLayer layer = new CAShapeLayer(); layer.Frame = frame; layer.Path = path.CGPath; return layer; }
CAShapeLayer CreateRingLayer(PointF center, float radius, float lineWidth, UIColor color) { var smoothedPath = CreateCirclePath (center, radius, 72); var slice = new CAShapeLayer (); slice.Frame = new RectangleF (center.X - radius, center.Y - radius, radius * 2, radius * 2); slice.FillColor = UIColor.Clear.CGColor; slice.StrokeColor = color.CGColor; slice.LineWidth = lineWidth; slice.LineCap = CAShapeLayer.JoinBevel; slice.LineJoin = CAShapeLayer.JoinBevel; slice.Path = smoothedPath.CGPath; return slice; }
private void DrawMarker (CGRect rowRect, float position) { if (Layer.Sublayers != null) { Layer.Sublayers = new CALayer[0]; } var visibleRect = Layer.Bounds; var currentTimeRect = visibleRect; // The red band of the timeMaker will be 7 pixels wide currentTimeRect.X = 0f; currentTimeRect.Width = 7f; var timeMarkerRedBandLayer = new CAShapeLayer (); timeMarkerRedBandLayer.Frame = currentTimeRect; timeMarkerRedBandLayer.Position = new CGPoint (rowRect.X, Bounds.Height / 2f); var linePath = CGPath.FromRect (currentTimeRect); timeMarkerRedBandLayer.FillColor = UIColor.FromRGBA (1.00f, 0.00f, 0.00f, 0.50f).CGColor; timeMarkerRedBandLayer.Path = linePath; currentTimeRect.X = 0f; currentTimeRect.Width = 1f; CAShapeLayer timeMarkerWhiteLineLayer = new CAShapeLayer (); timeMarkerWhiteLineLayer.Frame = currentTimeRect; timeMarkerWhiteLineLayer.Position = new CGPoint (3f, Bounds.Height / 2f); CGPath whiteLinePath = CGPath.FromRect (currentTimeRect); timeMarkerWhiteLineLayer.FillColor = UIColor.FromRGBA (1.00f, 1.00f, 1.00f, 1.00f).CGColor; timeMarkerWhiteLineLayer.Path = whiteLinePath; timeMarkerRedBandLayer.AddSublayer (timeMarkerWhiteLineLayer); CABasicAnimation scrubbingAnimation = new CABasicAnimation (); scrubbingAnimation.KeyPath = "position.x"; scrubbingAnimation.From = new NSNumber (HorizontalPositionForTime (CMTime.Zero)); scrubbingAnimation.To = new NSNumber (HorizontalPositionForTime (duration)); scrubbingAnimation.RemovedOnCompletion = false; scrubbingAnimation.BeginTime = 0.000000001; scrubbingAnimation.Duration = duration.Seconds; scrubbingAnimation.FillMode = CAFillMode.Both; timeMarkerRedBandLayer.AddAnimation (scrubbingAnimation, null); if (Player != null) { Console.WriteLine ("Duration in seconds - " + Player.CurrentItem.Asset.Duration.Seconds); var syncLayer = new AVSynchronizedLayer () { PlayerItem = Player.CurrentItem, }; syncLayer.AddSublayer (timeMarkerRedBandLayer); Layer.AddSublayer (syncLayer); } }
public override void AnimateTransition (IUIViewControllerContextTransitioning transitionContext) { //1 _transitionContext = transitionContext; //2 var containerView = _transitionContext.ContainerView; var fromViewController = _transitionContext.GetViewControllerForKey (UITransitionContext.FromViewControllerKey) as OnboardingController; var toViewController = _transitionContext.GetViewControllerForKey (UITransitionContext.ToViewControllerKey) as ContainerController; var fromRect = fromViewController.NavigationRect; var toRect = new CGRect (-toViewController.View.Bounds.Width / 2, -toViewController.View.Bounds.Height / 2, toViewController.View.Bounds.Width * 2, toViewController.View.Bounds.Height * 2); //3 containerView.AddSubview(toViewController.View); //4 var circleMaskPathInitial = UIBezierPath.FromRoundedRect(fromRect, fromRect.Height/2); var circleMaskPathFinal = UIBezierPath.FromRoundedRect (toRect, toRect.Height/2); //5 var maskLayer = new CAShapeLayer(); maskLayer.Path = circleMaskPathFinal.CGPath; toViewController.View.Layer.Mask = maskLayer; //6 var maskLayerAnimation = CABasicAnimation.FromKeyPath("path"); maskLayerAnimation.SetFrom(circleMaskPathInitial.CGPath); maskLayerAnimation.SetTo(circleMaskPathFinal.CGPath); maskLayerAnimation.Duration = TransitionDuration(_transitionContext); maskLayerAnimation.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.EaseIn); maskLayerAnimation.AnimationStopped += (object sender, CAAnimationStateEventArgs e) => { if(_transitionContext != null) { _transitionContext.CompleteTransition (!_transitionContext.TransitionWasCancelled); var controller = _transitionContext.GetViewControllerForKey (UITransitionContext.FromViewControllerKey); if(controller != null) { controller.View.Layer.Mask = null; } } }; maskLayer.AddAnimation (maskLayerAnimation, "path"); }
public ODRefreshControl (UIScrollView scrollView, ODRefreshControlLayout layout = ODRefreshControlLayout.Vertical, UIView activity = null) : base ( (layout == ODRefreshControlLayout.Vertical) ? new RectangleF (0, (-TotalViewHeight - scrollView.ContentInset.Top), scrollView.Bounds.Width, TotalViewHeight) : new RectangleF ((-TotalViewHeight - scrollView.ContentInset.Left), 0, TotalViewHeight, scrollView.Bounds.Height) ) { ScrollView = scrollView; OriginalContentInset = scrollView.ContentInset; _vertical = (layout == ODRefreshControlLayout.Vertical); AutoresizingMask = (_vertical) ? UIViewAutoresizing.FlexibleWidth : UIViewAutoresizing.FlexibleHeight; ScrollView.AddSubview (this); ScrollView.AddObserver (this, new NSString ("contentOffset"), NSKeyValueObservingOptions.New, IntPtr.Zero); ScrollView.AddObserver (this, new NSString ("contentInset"), NSKeyValueObservingOptions.New, IntPtr.Zero); _activity = activity ?? new UIActivityIndicatorView (UIActivityIndicatorViewStyle.Gray); _activity.Center = new PointF ((float) Math.Floor (Bounds.Width / 2.0f), (float) Math.Floor (Bounds.Height / 2.0f)); _activity.AutoresizingMask = (_vertical) ? UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin : UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleBottomMargin; _activity.Alpha = 1; if (_activity is UIActivityIndicatorView) { ((UIActivityIndicatorView) _activity).StartAnimating (); } AddSubview (_activity); _refreshing = false; _canRefresh = true; _ignoreInset = false; _ignoreOffset = false; _didSetInset = false; _hasSectionHeaders = false; _tintColor = UIColor.FromRGB (155, 162, 172); _shadowColor = UIColor.Black; _highlightColor = UIColor.White.ColorWithAlpha (.2f); _shapeLayer = new CAShapeLayer { FillColor = _tintColor.CGColor, StrokeColor = UIColor.DarkGray.ColorWithAlpha (.5f).CGColor, LineWidth = .5f, ShadowColor = _shadowColor.CGColor, ShadowOffset = new SizeF (0, 1), ShadowOpacity = .4f, ShadowRadius = .5f }; Layer.AddSublayer (_shapeLayer); _arrowLayer = new CAShapeLayer { StrokeColor = UIColor.DarkGray.ColorWithAlpha (.5f).CGColor, LineWidth = .5f, FillColor = UIColor.White.CGColor }; _shapeLayer.AddSublayer (_arrowLayer); _highlightLayer = new CAShapeLayer { FillColor = _highlightColor.CGColor }; _shapeLayer.AddSublayer (_highlightLayer); if (!_vertical) { // Highlight layer is currently not shown in horizontal mode // because it has a wrong path. // It should instead be drawn all the way from left to right circle. // Feel free to work on it! _highlightLayer.RemoveFromSuperLayer (); } }
/** Forces a redraw of the entire check box. * The current value of On is kept. */ public void Reload() { if (_offBoxLayer != null) _offBoxLayer.RemoveFromSuperLayer(); _offBoxLayer = null; if (_onBoxLayer != null) _onBoxLayer.RemoveFromSuperLayer(); _onBoxLayer = null; if (_checkMarkLayer != null) _checkMarkLayer.RemoveFromSuperLayer(); _checkMarkLayer = null; SetNeedsDisplay(); LayoutIfNeeded(); }
private void DrawCheckMark() { if (_checkMarkLayer != null) _checkMarkLayer.RemoveFromSuperLayer(); _checkMarkLayer = new CAShapeLayer { Frame = Bounds, Path = _pathManager.PathForCheckMark().CGPath, FillColor = UIColor.Clear.CGColor, StrokeColor = _checkColor.CGColor, LineWidth = _lineWidth, LineCap = new NSString("kCALineCapRound"), LineJoin = new NSString("kCALineJoinRound"), RasterizationScale = 2 * UIScreen.MainScreen.Scale, ShouldRasterize = true }; Layer.AddSublayer(_checkMarkLayer); }
void SetupPhotos() { nfloat height = this.Frame.Size.Height; nfloat width = this.Frame.Size.Width; cp_mask = new UIView(new CGRect(0, 0, width, height * Constants.CP_RATIO)); pp_mask = new UIView(new CGRect(width * Constants.PP_X_RATIO, height * Constants.PP_Y_RATIO, height * Constants.PP_RATIO, height * Constants.PP_RATIO)); pp_circle = new UIView(new CGRect(pp_mask.Frame.Location.X - Constants.PP_BUFF, pp_mask.Frame.Location.Y - Constants.PP_BUFF, pp_mask.Frame.Size.Width + 2 * Constants.PP_BUFF, pp_mask.Frame.Size.Height + 2 * Constants.PP_BUFF)); pp_circle.BackgroundColor = UIColor.White; pp_circle.Layer.CornerRadius = pp_circle.Frame.Size.Height / 2; pp_mask.Layer.CornerRadius = pp_mask.Frame.Size.Height / 2; cp_mask.BackgroundColor = new UIColor(0.98f, 0.98f, 0.98f, 1); nfloat cornerRadius = this.Layer.CornerRadius; UIBezierPath maskPath = UIBezierPath.FromRoundedRect(cp_mask.Bounds, UIRectCorner.TopLeft | UIRectCorner.TopRight, new CGSize(cornerRadius, cornerRadius)); CAShapeLayer maskLayer = new CAShapeLayer(); maskLayer.Frame = cp_mask.Bounds; maskLayer.Path = maskPath.CGPath; cp_mask.Layer.Mask = maskLayer; UIBlurEffect blurEffect = UIBlurEffect.FromStyle(UIBlurEffectStyle.Light); visualEffectView = new UIVisualEffectView(blurEffect); visualEffectView.Frame = cp_mask.Frame; visualEffectView.Alpha = 0; profileImageView = new UIImageView(); profileImageView.Frame = new CGRect(0, 0, pp_mask.Frame.Size.Width, pp_mask.Frame.Size.Height); coverImageView = new UIImageView(); coverImageView.Frame = cp_mask.Frame; coverImageView.ContentMode = UIViewContentMode.ScaleAspectFill; cp_mask.AddSubview(coverImageView); pp_mask.AddSubview(profileImageView); cp_mask.ClipsToBounds = true; pp_mask.ClipsToBounds = true; // setup the label nfloat titleLabelX = pp_circle.Frame.Location.X + pp_circle.Frame.Size.Width; titleLabel = new UILabel(new CGRect(titleLabelX, cp_mask.Frame.Size.Height + 7, this.Frame.Size.Width - titleLabelX, 26)); titleLabel.AdjustsFontSizeToFitWidth = false; titleLabel.LineBreakMode = UILineBreakMode.Clip; titleLabel.Font = UIFont.FromName("HelveticaNeue-Light", 20); titleLabel.TextColor = new UIColor(0, 0, 0, 0.8f); titleLabel.Text = "Title Label"; titleLabel.UserInteractionEnabled = true; UITapGestureRecognizer tapGesture = new UITapGestureRecognizer(this.TitleLabelTap); titleLabel.AddGestureRecognizer(tapGesture); coverImageView.UserInteractionEnabled = true; UITapGestureRecognizer tapGestureCover = new UITapGestureRecognizer(this.CoverPhotoTap); coverImageView.AddGestureRecognizer(tapGestureCover); profileImageView.UserInteractionEnabled = true; UITapGestureRecognizer tapGestureProfile = new UITapGestureRecognizer(this.ProfilePhotoTap); profileImageView.AddGestureRecognizer(tapGestureProfile); this.AddSubview(titleLabel); this.AddSubview(cp_mask); this.AddSubview(pp_circle); this.AddSubview(pp_mask); coverImageView.AddSubview(visualEffectView); }
private void DrawOnBox() { if (_onBoxLayer != null) _onBoxLayer.RemoveFromSuperLayer(); _onBoxLayer = new CAShapeLayer { Frame = Bounds, Path = _pathManager.PathForBox().CGPath, FillColor = _fillColor.CGColor, StrokeColor = _ontintColor.CGColor, LineWidth = _lineWidth, RasterizationScale = 2 * UIScreen.MainScreen.Scale, ShouldRasterize = true }; Layer.AddSublayer(_onBoxLayer); }
public void SetMagnitudes (double [] magnitudeData) { if (curveLayer == null) { curveLayer = new CAShapeLayer (); curveLayer.FillColor = UIColor.FromRGBA (0.31f, 0.37f, 0.73f, 0.8f).CGColor; graphLayer.AddSublayer (curveLayer); } var bezierPath = new CGPath (); var width = graphLayer.Bounds.Width; bezierPath.MoveToPoint (leftMargin, graphLayer.Frame.Height + bottomMargin); float lastDbPos = 0f; float location = leftMargin; var frequencyCount = frequencies?.Count ?? 0; var pixelRatio = (int)(Math.Ceiling (width / frequencyCount)); for (int i = 0; i < frequencyCount; i++) { var dbValue = 20 * Math.Log10 (magnitudeData [i]); float dbPos; if (dbValue < -defaultGain) dbPos = GetLocationForDbValue (-defaultGain); else if (dbValue > defaultGain) dbPos = GetLocationForDbValue (defaultGain); else dbPos = GetLocationForDbValue ((float)dbValue); if (Math.Abs (lastDbPos - dbPos) >= 0.1) bezierPath.AddLineToPoint (location, dbPos); lastDbPos = dbPos; location += pixelRatio; if (location > width + graphLayer.Frame.X) { location = (float)width + (float)graphLayer.Frame.X; break; } } bezierPath.AddLineToPoint (location, graphLayer.Frame.Y + graphLayer.Frame.Height + bottomMargin); bezierPath.CloseSubpath (); CATransaction.Begin (); CATransaction.DisableActions = true; curveLayer.Path = bezierPath; CATransaction.Commit (); UpdateControls (true); }
public override void ViewDidLoad() { base.ViewDidLoad (); // Create active region rectangle _rectLayer = new CAShapeLayer (); _rectLayer.FillColor = UIColor.FromRGBA (1.0f, 0.0f, 0.0f, 0.2f).CGColor; _rectLayer.StrokeColor = UIColor.White.CGColor; _rectLayer.LineWidth = 3; _rectLayer.AnchorPoint = PointF.Empty; this.View.Layer.AddSublayer (_rectLayer); // get is device silent flag _isSilent = NSUserDefaults.StandardUserDefaults.BoolForKey("silent_pref"); // set camera view //parentPicker.CameraView = cameraView; }
private void OnRequestHeaderImages (List<string> images) { var defaultImage = UIImage.FromFile (ViewModel.DefaultAccountImageName); AccountImageView.Hidden = images.Count == 0; // clear all existing entries before beginning foreach (UIView view in AccountsView.Subviews) { if(!view.Equals(AccountImageView)) { AccountsView.RemoveConstraints (view.Constraints); view.RemoveFromSuperview (); } } if(images.Count > 0) { // proceed and add the new ones var prevImageView = AccountImageView; var prevTrailingConstraint = AccountImageViewTrailingConstraint; var rect = CGRect.FromLTRB (prevImageView.Frame.X + 2, prevImageView.Frame.Y + 2, prevImageView.Frame.Width - 4, prevImageView.Frame.Height - 4); var path = UIBezierPath.FromRoundedRect (rect, prevImageView.Frame.Height / 2); var prevMaskLayer = new CAShapeLayer (); if(!AccountsView.Constraints.Contains(AccountImageViewTrailingConstraint)) { AccountsView.AddConstraint (AccountImageViewTrailingConstraint); } prevMaskLayer.Path = path.CGPath; prevMaskLayer.ShadowColor = UIColor.Black.CGColor; prevMaskLayer.ShadowOpacity = 0.35f; prevMaskLayer.ShadowOffset = new CGSize (0, 1); prevMaskLayer.ShadowRadius = 2; prevMaskLayer.ShadowPath = path.CGPath; prevImageView.ClipsToBounds = false; prevImageView.Layer.Mask = prevMaskLayer; prevImageView.Layer.MasksToBounds = false; prevImageView.SetImage (new NSUrl(images [0]), defaultImage); images.RemoveAt (0); AccountsView.Layer.MasksToBounds = false; AccountsView.ClipsToBounds = false; foreach (string imageUrl in images) { var imageView = new UIImageView (); var maskLayer = new CAShapeLayer (); maskLayer.Path = path.CGPath; maskLayer.ShadowColor = prevMaskLayer.ShadowColor; maskLayer.ShadowOpacity = prevMaskLayer.ShadowOpacity; maskLayer.ShadowOffset = prevMaskLayer.ShadowOffset; maskLayer.ShadowRadius = prevMaskLayer.ShadowRadius; maskLayer.ShadowPath = prevMaskLayer.ShadowPath; imageView.ClipsToBounds = prevImageView.ClipsToBounds; imageView.Layer.Mask = maskLayer; imageView.Layer.MasksToBounds = prevImageView.Layer.MasksToBounds; imageView.TranslatesAutoresizingMaskIntoConstraints = false; imageView.SetImage (new NSUrl (imageUrl), defaultImage); var heightConstraint = NSLayoutConstraint.Create (imageView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, prevImageView.Frame.Height); var widthConstraint = NSLayoutConstraint.Create (imageView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, prevImageView.Frame.Width); var leadingConstraint = NSLayoutConstraint.Create (imageView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, prevImageView, NSLayoutAttribute.Trailing, 1, -prevImageView.Frame.Width/2); var centerYConstraint = NSLayoutConstraint.Create (imageView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, AccountsView, NSLayoutAttribute.CenterY, 1, 0); var trailingConstraint = NSLayoutConstraint.Create (imageView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, AccountsView, NSLayoutAttribute.Trailing, 1, 0); AccountsView.AddSubview (imageView); AccountsView.SendSubviewToBack (imageView); AccountsView.RemoveConstraint (prevTrailingConstraint); AccountsView.AddConstraint (heightConstraint); AccountsView.AddConstraint (widthConstraint); AccountsView.AddConstraint (leadingConstraint); AccountsView.AddConstraint (centerYConstraint); AccountsView.AddConstraint (trailingConstraint); prevMaskLayer = maskLayer; prevImageView = imageView; prevTrailingConstraint = trailingConstraint; } AccountsView.LayoutIfNeeded (); } }