聚焦时,文本在UITextField中跳转

时间:2015-05-19 19:38:26

标签: c# ios objective-c mono xamarin.ios

我处理这个奇怪的问题...... UITextField内的文字在聚焦时跳转。

https://www.youtube.com/watch?v=6AkgWXkmBwE

它是我创建的自定义UIView,并在另一个UIViewController中使用。 我已经尝试删除了Draw功能,但没有工作。删除了所有样式和字体......没有变化。

知道什么是错的吗?

using System;
using UIKit;
using Foundation;
using System.Drawing;
using CoreGraphics;

namespace whatever
{
    [Register("LoginPanelView")]
    public class LoginPanelView : UIView
    {

        public UITextField UserNameField { get; private set; }

        public UITextField PasswordField { get; private set; }

        private const float HorizontalMargin = 15;

        public LoginPanelView(IntPtr handle)
            : base(handle)
        {

            UserNameField = new UITextField();
            PasswordField = new UITextField();

            UserNameField.Placeholder = "Username";
            PasswordField.Placeholder = "Password";

            UserNameField.Font = UIFont.FromName("Avenir", 14);
            PasswordField.Font = UIFont.FromName("Avenir", 14);
            PasswordField.SecureTextEntry = true;

            AddSubviews(new [] { UserNameField, PasswordField });

            Layer.CornerRadius = 5.0f;
            Layer.BorderColor = UIColor.Gray.CGColor;
            ClipsToBounds = true;

        }

        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            var height = (float)(Bounds.Height / 2);
            UserNameField.Frame = new RectangleF(HorizontalMargin, 0, (float)Bounds.Width - (2 * HorizontalMargin), height);
            PasswordField.Frame = new RectangleF(HorizontalMargin, height, (float)Bounds.Width - (2 * HorizontalMargin), height);
        }

        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            var graphicsContext = UIGraphics.GetCurrentContext();
            var height = (float)(Bounds.Height / 2);

            graphicsContext.SetLineWidth(0.25f);
            graphicsContext.SetStrokeColor(Layer.BorderColor);

            // create some cutout geometry
            var path = new CGPath();
            path.AddLines(new CGPoint[]
                {
                    new PointF(0, height),
                    new PointF((float)Bounds.Width, height)
                });
            path.CloseSubpath();

            graphicsContext.AddPath(path);
            graphicsContext.DrawPath(CGPathDrawingMode.Stroke);
        }
    }

}

0 个答案:

没有答案