开发者

How to add a UIActivityIndicator to a splash screen in a iphone application?

How to add a UIActivityIndicator to a splash screen ?

Edit : I tried the following things

I created UIViewController Sub class calle开发者_开发百科d SplashViewController. and the code is as below, still the image is not persisting long enough .


If by "Splash Screen" you mean the image that is displayed when your app launches, the answer is that you can't.

What you can do is have an initial view that includes a background image that looks just like your launch image, and then add an activity indicator into that view. To the user, it will appear that the activity indicator is "part" of your launch image.

The trick is to load your initial nib as quickly as possible (keep it small and simple) so the static images transitions to a view you can manipulate right away.


It depends on what you mean by a splash screen. If you mean the image that is first shown when the app is run, then we have a more tricky situation. This is just a static image (Default.png) so what you would then need to do is create a view that has your splash screen image as the background, add the activity indicator view on top of it, and then add that view directly from the app delegate. When whatever you're loading is done, you can get rid of this view and proceed with the rest of your program. Probably easier to do in a NIB, but here's an idea of it programmatically:

- (void)loadView;
{
    CGRect r = [UIScreen mainScreen].applicationFrame;
    UIView *activityView = [[[UIView alloc] initWithFrame:r] autorelease];
    self.view = activityView;

    activityView.backgroundColor = [UIColor blackColor];
    activityView.alpha = 0.5;

    UIImageView *imgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]] autorelease];
    [activityView addSubview:imgView];

    CGRect wheelR = CGRectMake(r.size.width / 2 - 12, r.size.height / 2 - 12, 24, 24);
    UIActivityIndicatorView *activityWheel = [[UIActivityIndicatorView alloc] initWithFrame:wheelR];
    activityWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
    activityWheel.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                    UIViewAutoresizingFlexibleRightMargin |
                                    UIViewAutoresizingFlexibleTopMargin |
                                    UIViewAutoresizingFlexibleBottomMargin);
    [activityWheel startAnimating];
    [activityView addSubview:activityWheel];
}


Hi Pradeep I implement this code in monotouch for ios so this code is help ful to implement your logic

#region Splash Screen
public  void  ShowSplash(){
// get the Height & Width of device Screen
float mainSrcWidth = this.View.Bounds.Width; 
float mainSrcHeight = this.View.Bounds.Height;
splashScreen = new UIImageView (UIImage.FromFile ("Images/loadNew1536_2008.png"));
splashScreen.Frame = new RectangleF (0, 0, mainSrcWidth, mainSrcHeight);    
//Start the thread;
ThreadPool.QueueUserWorkItem (delegate {
Load ();
}
)
this.View.AddSubview(splashScreen);
}
#endregion


#region Load() splashscreen
private void Load ()
//Sleep for 3 seconds to simulate a long load.
Thread.Sleep (new TimeSpan (0, 0, 0, 3));
this.BeginInvokeOnMainThread (delegate {
splashScreen.RemoveFromSuperview ();
splashScreen = null;
});
}
#endregion

Call the ShowSplash() method from Appdelegate Class of FinishedLaunching Method


UIActivityIndicators are UIViews and can be added like any other.

something like: [myView addSubview:mySpinner];

Or just drop one in your NIB.

here's another answer: How to use activity indicator view on iPhone?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜