예제 #1
0
		protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
		{
			base.OnElementChanged(e);

			if ((Control != null) && (e.NewElement != null))
			{
				Control.Tag = ((RoundButton)e.NewElement).Tag;
				Control.TouchUpInside += (sender, ev) =>
				{
					var responder = InputTools.FindFirstResponder(UIApplication.SharedApplication.KeyWindow.RootViewController.View);
					if (responder != null)
						responder.ResignFirstResponder();
				};
			}
		}
        private void OnKeyboardNotification(NSNotification notification)
        {
            float neededOffset  = 0;
            var   visible       = notification.Name == UIKeyboard.WillShowNotification;
            var   keyboardFrame = visible ? UIKeyboard.FrameEndFromNotification(notification) : UIKeyboard.FrameBeginFromNotification(notification);

            if (visible)
            {
                KeyboardShown?.Invoke(this, (float)keyboardFrame.Height);
            }

            var  parentView = UIApplication.SharedApplication.KeyWindow.RootViewController.View;
            bool isSubview  = false;
            var  responder  = InputTools.FindFirstResponder(parentView);

            if ((responder == null) && (UIApplication.SharedApplication.KeyWindow.Subviews != null))
            {
                foreach (var subview in UIApplication.SharedApplication.KeyWindow.Subviews)
                {
                    responder = InputTools.FindFirstResponder(subview);
                    if (responder != null)
                    {
                        parentView = subview;
                        isSubview  = true;
                        break;
                    }
                }
            }

            if (responder != null)
            {
                var offsetFromBottom = getOffsetFromBottom(responder);
                if (responder.Tag > 0)
                {
                    var views = getTaggedViews(parentView, responder.Tag);
                    if (views.Any())
                    {
                        var offsets = new List <nfloat>();
                        foreach (var view in views)
                        {
                            offsets.Add(getOffsetFromBottom(view));
                        }

                        offsetFromBottom = offsets.Min();
                    }
                }

                if (keyboardFrame.Height > offsetFromBottom)
                {
                    neededOffset = (float)(keyboardFrame.Height - offsetFromBottom + responder.Frame.Height);
                }
            }

            if ((KeyboardChanged != null) && ((neededOffset > 0) || !visible))
            {
                if (isSubview)
                {
                    parentView.Transform = CoreGraphics.CGAffineTransform.MakeTranslation(0, -neededOffset);
                }
                else
                {
                    KeyboardChanged(this, new KeyboardHelperEventArgs(visible, (float)keyboardFrame.Height, neededOffset));
                }
            }
        }