Xcode 导致缺乏用户体验的组件初始化缓慢

Xcode 导致缺乏用户体验的组件初始化缓慢,xcode,uiview,uiviewcontroller,xamarin.ios,Xcode,Uiview,Uiviewcontroller,Xamarin.ios,这是我在上一个视图上单击按钮时显示的视图。 文本框、笑脸图像和标签是由xCode预先设计的 请查看视图的图像和代码,以了解为什么视图的所有组件都初始化得非常慢,并准备在完成完全加载后进行我捕获的最后一次拍摄。此外,我打字时速度非常慢,当我用iOS在文本框上的每次触摸都提供的键盘打字时,字母的显示速度非常慢 视图的代码 using System; using System.Drawing; using MonoTouch.Foundation; using MonoTouch.UIKit;

这是我在上一个视图上单击按钮时显示的视图。 文本框、笑脸图像和标签是由xCode预先设计的

请查看视图的图像和代码,以了解为什么视图的所有组件都初始化得非常慢,并准备在完成完全加载后进行我捕获的最后一次拍摄。此外,我打字时速度非常慢,当我用iOS在文本框上的每次触摸都提供的键盘打字时,字母的显示速度非常慢

视图的代码

using System;
using System.Drawing;

using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace IstanbulCity
{
    public partial class AskForNAme : UIViewController
    {
        public delegate void AskForNAmeClosingDelegate (AskForNAme form);

        public event AskForNAmeClosingDelegate AskForNAmeClosed;
        NSObject obs1;
        float scrollamount = 0.0f;
        float bottomPoint = 0.0f;
        float yOffset = 0.2f;
        bool moveViewUp = false;

        public AskForNAme () : base ("AskForNAme", null)
        {


        }

        public override void DidReceiveMemoryWarning ()
        {
            // Releases the view if it doesn't have a superview.
            base.DidReceiveMemoryWarning ();

            // Release any cached data, images, etc that aren't in use.
        }

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


            // Perform any additional setup after loading the view, typically from a nib.
        }
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(true);
                obs1 = NSNotificationCenter.DefaultCenter.AddObserver (
"UIKeyboardDidShowNotification", KeyboardUpNotification);
            this.tbOwnerMailAdress.ShouldReturn += TextFieldShouldReturn;
            this.tbOwnerBirthDay.ShouldReturn += TextFieldShouldReturn;
            this.uivGuguPhoto.Image = UIImage.FromFile ("image/fcuk.jpeg");

        }
        public override void ViewWillAppear(bool animated)
        {  
            base.ViewWillAppear(false);
            obs1 = NSNotificationCenter.DefaultCenter.AddObserver (
"UIKeyboardDidShowNotification", KeyboardUpNotification);
            this.tbOwnerMailAdress.ShouldReturn += TextFieldShouldReturn;
            this.tbOwnerBirthDay.ShouldReturn += TextFieldShouldReturn;
            this.uivGuguPhoto.Image = UIImage.FromFile ("image/fcuk.jpeg");

        }
        public override void ViewDidUnload ()
        {
            base.ViewDidUnload ();

            // Clear any references to subviews of the main view in order to
            // allow the Garbage Collector to collect them sooner.
            //
            // e.g. myOutlet.Dispose (); myOutlet = null;

            ReleaseDesignerOutlets ();
        }

        public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
        {
            // Return true for supported orientations
            return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
        }

        void HandleIstanbulCityViewControllerClosed (babyAge form)
        {
            form.DismissModalViewControllerAnimated (true);
            form = null;
        }



        partial void tbKadikoyHallEditDidEndOnExit (MonoTouch.Foundation.NSObject sender)
        {
            tbIstanbulName.ResignFirstResponder ();
        }



        private bool TextFieldShouldReturn (UITextField tf)
        {
            tf.ResignFirstResponder ();
            if (moveViewUp) {
                ScrollTheView (false);
            }
            return true;
        }

        private void KeyboardUpNotification (NSNotification notification)
        {
            ResetTheView ();

            RectangleF r = UIKeyboard.BoundsFromNotification (notification);

            if (this.tbOwnerMailAdress.IsEditing ) {
                //Calculate the bottom of the Texbox
                //plus a small margin...
                bottomPoint = (this.tbOwnerMailAdress.Frame.Y + this.tbOwnerMailAdress.Frame.Height + yOffset);

                //Calculate the amount to scroll the view
                //upwards so the Textbox becomes visible...
                //This is the height of the Keyboard -
                //(the height of the display - the bottom
                //of the Texbox)... 
                scrollamount = (r.Height - (View.Frame.Size.Height - bottomPoint));
            }
            else if (this.tbOwnerBirthDay.IsEditing)
            {
                bottomPoint = (this.tbOwnerBirthDay.Frame.Y + this.tbOwnerBirthDay.Frame.Height + yOffset);
                scrollamount = (r.Height - (View.Frame.Size.Height - bottomPoint));
            }
            else
            {
                scrollamount = 0;
            }

            //Check to see whether the view
            //should be moved up...
            if (scrollamount > 0) {
                moveViewUp = true;
                ScrollTheView (moveViewUp);
            }  else
                moveViewUp = false;
        }

        private void ResetTheView ()
        {
            UIView.BeginAnimations (string.Empty, System.IntPtr.Zero);
            UIView.SetAnimationDuration (0.3);

            RectangleF frame = View.Frame;
            frame.Y = 0;
            View.Frame = frame;
            UIView.CommitAnimations ();
        }

        private void ScrollTheView (bool movedUp)
        {
//To invoke a views built-in animation behaviour,
//you create an animation block and
//set the duration of the move...
//Set the display scroll animation and duration...
            UIView.BeginAnimations (string.Empty, System.IntPtr.Zero);
            UIView.SetAnimationDuration (0.3);

//Get Display size...
            RectangleF frame = View.Frame;

            if (movedUp) {
//If the view should be moved up,
//subtract the keyboard height from the display...
                frame.Y -= scrollamount;
            }  else {
//If the view shouldn't be moved up, restore it
//by adding the keyboard height back to the original...
                frame.Y += scrollamount;
            }

//Assign the new frame to the view...
            View.Frame = frame;

//Tell the view that your all done with setting
//the animation parameters, and it should
//start the animation...
            UIView.CommitAnimations ();

        }
    }
}
最新版本-仍然是相同的用户体验“慢

using System;
using System.Drawing;

using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace IstanbulCity
{
    public partial class AskForNAme : UIViewController
    {
        public delegate void AskForNAmeClosingDelegate (AskForNAme form);

        public event AskForNAmeClosingDelegate AskForNAmeClosed;


        public AskForNAme () : base ("AskForNAme", null)
        {


        }

        public override void DidReceiveMemoryWarning ()
        {
            // Releases the view if it doesn't have a superview.
            base.DidReceiveMemoryWarning ();

            // Release any cached data, images, etc that aren't in use.
        }

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


            // Perform any additional setup after loading the view, typically from a nib.
        }


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

            // Clear any references to subviews of the main view in order to
            // allow the Garbage Collector to collect them sooner.
            //
            // e.g. myOutlet.Dispose (); myOutlet = null;

            ReleaseDesignerOutlets ();
        }

        public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
        {
            // Return true for supported orientations
            return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
        }

        void HandleIstanbulCityViewControllerClosed (babyAge form)
        {
            form.DismissModalViewControllerAnimated (true);
            form = null;
        }







    }
}

这看起来与初始化无关。您正在添加来自
ViewDidAspect
ViewWillAspect
的通知。您还可以始终调用
重置视图
,该视图在每次键盘通知中都会显示动画(即使没有其他更改)

我猜您调用
ResetTheView
的频率比您意识到的要高,而且连续的动画正在破坏应用程序的性能


您可以通过在
重置视图
方法中放置一个
控制台。WriteLine
,或者一个计数器来确认这一点。

先生,我已经删除了所有关于键盘出现和消失操作的行。现在,视图的代码很简单,只包含了一些基本内容,但加载速度仍然与以前相同。我期待很多东西吗?是诺拉花了将近7秒钟才看到文本框吗?乍一看,我看到的边界几乎可见,比7-8秒后,文本框可见得非常好。。。我更新了代码文件的最新一行。启动任何iOS应用程序都需要几秒钟(根据您使用的设备的不同,可能会有很大的变化)。苹果建议你使用一个看起来像你的初始应用程序状态的闪屏,这样对用户来说它看起来更快(这比黑屏要好得多)。特定于MonoTouch,请确保使用发布版本来测试性能。调试版本更大(调试符号)和更慢(优化更少,它们尝试连接到调试器),因此它们不会显示应用程序的实际/最终性能。