Exemplo n.º 1
0
        CGPoint PointOnCircle(CGPoint center, float radius, float angleInDegrees)
        {
            float x = radius * (float)Math.Cos(angleInDegrees * Math.PI / 180) + radius;
            float y = radius * (float)Math.Sin(angleInDegrees * Math.PI / 180) + radius;

            return(new CGPoint(x, y));
        }
Exemplo n.º 2
0
        public override void Draw(CGRect rect)
        {
            using (var context = UIGraphics.GetCurrentContext())
            {
                switch (_maskType)
                {
                case MaskType.Black:
                    UIColor.FromWhiteAlpha(0f, 0.5f).SetColor();
                    context.FillRect(Bounds);
                    break;

                case MaskType.Gradient:
                    nfloat[] colors    = new nfloat[] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f };
                    nfloat[] locations = new nfloat[] { 0.0f, 1.0f };
                    using (var colorSpace = CGColorSpace.CreateDeviceRGB())
                    {
                        using (var gradient = new CGGradient(colorSpace, colors, locations))
                        {
                            var   center = new CGPoint(Bounds.Size.Width / 2, Bounds.Size.Height / 2);
                            float radius = Math.Min((float)Bounds.Size.Width, (float)Bounds.Size.Height);
                            context.DrawRadialGradient(gradient, center, 0, center, radius, CGGradientDrawingOptions.DrawsAfterEndLocation);
                        }
                    }

                    break;
                }
            }
        }
Exemplo n.º 3
0
        CAShapeLayer CreateRingLayer(CGPoint center, float radius, float lineWidth, UIColor color)
        {
            var smoothedPath = CreateCirclePath(center, radius, 72);
            var slice        = new CAShapeLayer();

            slice.Frame       = new CGRect(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);
        }
Exemplo n.º 4
0
        UIBezierPath CreateCirclePath(CGPoint center, float radius, int sampleCount)
        {
            var     smoothedPath = new UIBezierPath();
            CGPoint startPoint   = PointOnCircle(center, radius, -90);

            smoothedPath.MoveTo(startPoint);

            float delta          = 360 / sampleCount;
            float angleInDegrees = -90;

            for (int i = 1; i < sampleCount; i++)
            {
                angleInDegrees += delta;
                var point = PointOnCircle(center, radius, angleInDegrees);
                smoothedPath.AddLineTo(point);
            }
            smoothedPath.AddLineTo(startPoint);
            return(smoothedPath);
        }
Exemplo n.º 5
0
        void PositionHUD(NSNotification notification)
        {
            nfloat keyboardHeight    = 0;
            double animationDuration = 0;

            UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;
            bool ignoreOrientation             = UIDevice.CurrentDevice.CheckSystemVersion(8, 0);

            if (notification != null)
            {
                var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);
                animationDuration = UIKeyboard.AnimationDurationFromNotification(notification);

                if (notification.Name == UIKeyboard.WillShowNotification || notification.Name == UIKeyboard.DidShowNotification)
                {
                    if (ignoreOrientation || IsPortrait(orientation))
                    {
                        keyboardHeight = keyboardFrame.Size.Height;
                    }
                    else
                    {
                        keyboardHeight = keyboardFrame.Size.Width;
                    }
                }
                else
                {
                    keyboardHeight = 0;
                }
            }
            else
            {
                keyboardHeight = VisibleKeyboardHeight;
            }

            CGRect orientationFrame = this.Window.Bounds;
            CGRect statusBarFrame   = UIApplication.SharedApplication.StatusBarFrame;

            if (!ignoreOrientation && IsLandscape(orientation))
            {
                orientationFrame.Size = new CGSize(orientationFrame.Size.Height, orientationFrame.Size.Width);
                statusBarFrame.Size   = new CGSize(statusBarFrame.Size.Height, statusBarFrame.Size.Width);
            }

            var activeHeight = orientationFrame.Size.Height;

            if (keyboardHeight > 0)
            {
                activeHeight += statusBarFrame.Size.Height * 2;
            }

            activeHeight -= keyboardHeight;
            nfloat posY       = (float)Math.Floor(activeHeight * 0.45);
            nfloat posX       = orientationFrame.Size.Width / 2;
            nfloat textHeight = _stringLabel.Frame.Height / 2 + 40;

            switch (toastPosition)
            {
            case ToastPosition.Bottom:
                posY = activeHeight - textHeight;
                break;

            case ToastPosition.Center:
                // Already set above
                break;

            case ToastPosition.Top:
                posY = textHeight;
                break;

            default:
                break;
            }

            CGPoint newCenter;
            float   rotateAngle;

            if (ignoreOrientation)
            {
                rotateAngle = 0.0f;
                newCenter   = new CGPoint(posX, posY);
            }
            else
            {
                switch (orientation)
                {
                case UIInterfaceOrientation.PortraitUpsideDown:
                    rotateAngle = (float)Math.PI;
                    newCenter   = new CGPoint(posX, orientationFrame.Size.Height - posY);
                    break;

                case UIInterfaceOrientation.LandscapeLeft:
                    rotateAngle = (float)(-Math.PI / 2.0f);
                    newCenter   = new CGPoint(posY, posX);
                    break;

                case UIInterfaceOrientation.LandscapeRight:
                    rotateAngle = (float)(Math.PI / 2.0f);
                    newCenter   = new CGPoint(orientationFrame.Size.Height - posY, posX);
                    break;

                default:                         // as UIInterfaceOrientationPortrait
                    rotateAngle = 0.0f;
                    newCenter   = new CGPoint(posX, posY);
                    break;
                }
            }

            if (notification != null)
            {
                UIView.Animate(animationDuration,
                               0, UIViewAnimationOptions.AllowUserInteraction, delegate
                {
                    MoveToPoint(newCenter, rotateAngle);
                }, null);
            }
            else
            {
                MoveToPoint(newCenter, rotateAngle);
            }
        }
Exemplo n.º 6
0
 void MoveToPoint(CGPoint newCenter, float angle)
 {
     HudView.Transform = CGAffineTransform.MakeRotation(angle);
     HudView.Center    = newCenter;
 }