2012-04-09 58 views
1

這是在單擊先前視圖上的按鈕時出現的視圖。 文本框,笑臉圖像和標籤是由xCode創建的預先設計的。緩慢初始化導致用戶體驗不足的組件

請查看圖片和視圖的代碼,以清楚爲什麼所有視圖的組件都非常緩慢地初始化,並準備好在完成完全加載時爲我拍攝的最後一個拍攝。此外,當我輸入字母時,字體顯示非常緩慢,而我正在使用iOS提供的鍵盤輸入文字時,字母顯示得非常緩慢。

enter image description here

的查看代碼;

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; 
     } 







    } 
} 

回答

2

這看起來沒有初始化相關。您正在添加來自ViewDidAppearViewWillAppear的通知。你也總是呼籲ResetTheView,它做動畫,每個鍵盤通知(即使沒有其他改變)。

我的猜測是你打電話的方式更經常,你意識到 - 連續的動畫正在殺死你的應用程序的性能。

您可以通過在ResetTheView方法中加入Console.WriteLine以及一個計數器來確認。

+0

先生,我刪除了關於鍵盤出現和消失操作的所有行。現在,該視圖的代碼很簡單,只有基礎知識,但仍以與之前相同的加載時間速度。我期待很多事情嗎?是否諾拉需要將近7秒才能看到文本框?乍一看,我看到的邊界幾乎可見,比7-8秒後,文本框可見非常好...我更新了代碼文件的最新行。 – theklc 2012-04-09 19:29:27

+2

啓動任何iOS應用程序需要幾秒鐘的時間(根據您使用的設備不同,它可能會有很大差異)。 Apple建議您使用看起來像初始應用程序狀態的* splash *屏幕,以便用戶看起來更快(這比黑屏要好得多)。特定的MonoTouch請確保您使用** Release **版本來測試性能。 ** Debug **版本較大(調試符號),速度較慢(較少優化,它們嘗試連接到調試器),因此它們不會向您顯示應用程序的實際/最終性能。 – poupou 2012-04-09 19:41:49

相關問題