BigTed.ProgressHUD.PositionHUD C# (CSharp) Метод

PositionHUD() публичный Метод

public PositionHUD ( NSNotification notification ) : void
notification NSNotification
Результат void
        void PositionHUD(NSNotification notification)
        {
            nfloat keyboardHeight = 0;
            double animationDuration = 0;

            Frame = UIScreen.MainScreen.Bounds;

            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 = UIApplication.SharedApplication.KeyWindow.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);
            }
        }