2012-04-09 5 views
1

Diese Ansicht wird angezeigt, wenn ich auf eine Schaltfläche in einer vorherigen Ansicht klicke. Die Textfelder, das lächelnde Gesichtsbild und die Beschriftungen wurden von xCode erstellt.Langsam initialisierte Komponenten, die zu mangelnder Benutzererfahrung führen

Bitte beachten Sie das Bild und den Code der Ansicht, um zu klären, warum alle Komponenten der Ansicht sehr langsam initialisiert werden und bereit sind, den letzten Schuss zu geben, der von mir aufgenommen wird, wenn er vollständig geladen ist. Darüber hinaus ist es sehr langsam, wenn ich Buchstaben eintippe, die Buchstaben erscheinen sehr langsam, während ich mit der Tastatur tippe, die iOS bei jeder Berührung der Textbox liefert.

enter image description here

Der Code der View;

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(); 

     } 
    } 
} 

Die neueste Version - Still The Same User Experience‘langsam!

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







    } 
} 

Antwort

2

Dies scheint nicht auf die Initialisierung bezogen zu sein. Sie fügen Benachrichtigungen von ViewDidAppear und ViewWillAppear hinzu. Sie sind auch immer Aufruf ResetTheView, die Animationen, auf jeder Tastaturbenachrichtigung (auch wenn nichts anderes geändert hat).

Meine Vermutung ist, dass Sie häufiger ResetTheView aufrufen, dass Sie erkennen - und die kontinuierlichen Animationen die Leistung Ihrer Anwendung töten.

Sie können dies bestätigen, indem Sie einen , und vielleicht einen Zähler, in der ResetTheView Methode setzen.

+0

Sir, ich habe alle Zeilen über die Tastatur erscheinen und verschwinden Operationen gelöscht. Jetzt ist der Code der Ansicht klar mit nur Grundlagen, aber immer noch mit der gleichen Geschwindigkeit der Ladezeit wie zuvor. Erwarte ich viele Dinge? Ist es nora, dass es fast 7 Sekunden dauert, um die Textfelder absolut zu sehen? Auf den ersten Blick sehe ich die Grenzen fast sichtbar, als nach 7-8 Sekunden die Textbox sehr gut sichtbar ... Ich aktualisiere die letzte Zeile der Codedatei. – theklc

+2

Das Starten von iOS-Anwendungen dauert einige Sekunden (je nach verwendetem Gerät kann es sehr unterschiedlich sein). Apple empfiehlt Ihnen, einen * splash * -Bildschirm zu verwenden, der wie Ihr ursprünglicher Anwendungsstatus aussieht, so dass er für Benutzer schneller erscheint (das ist viel besser als ein schwarzer Bildschirm). MonoTouch-spezifisch Bitte stellen Sie sicher, dass Sie ** Release ** Builds verwenden, um die Leistung zu testen. ** Debug ** -Builds sind größer (Debug-Symbole) und langsamer (weniger Optimierungen und sie versuchen, eine Verbindung zum Debugger herzustellen), sodass sie nicht die tatsächliche/endgültige Leistung Ihrer Anwendung anzeigen. – poupou