Activity indicator loading before Wkwebview in objective c - objective-c

i am using wkwebview and loading an url in objective c. i need to show activity indicator before loading wkwebview. is there any delegate methods for wkwebview?
-(void)viewWillAppear:(BOOL)animated{
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[spinner setCenter:CGPointMake(160,124)];
[self.view addSubview:spinner];
spinner.tag = 100;
[spinner startAnimating];
_homeWebView.opaque = true;
// http://ispatialtec.com/birdathon.php
_homeWebView.userInteractionEnabled = true;
[_homeWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.adbirdathon.ae/Birdathon/index.html"]]];
[spinner stopAnimating];
}

Yes there is the WKNavigationDelegate method
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
So remove your spinner there.

Related

UI issues while using blocks

I am using MBProgressHUD to display a loading indicator on my app. When i want to change something at UI or i open a new screen inside block, i only see a blank white screen. Does anyone has an idea what am i missing in my code?
-(void)doSomething:(id)sender
{
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Please wait";
[HUD showAnimated:YES whileExecutingBlock:^{
NSDictionary* dictReturn = [ServerApi getItemDetails::itemId userId:userId;
NewScreenController* vc = [[NewScreenController alloc]init];
[self presentViewController:vc animated:YES completion:nil];
}];
}
MBProgressHUD doesn't execute the block in the main thread. That's why you shouldn't change UI there at all.
You should use the method with a completionBlock instead.
- (void)doSomething:(id)sender {
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Please wait";
dispatch_block_t executionBlock = ^{
self.dictReturn = [ServerApi getItemDetails:itemId userId:userId];
};
void (^completionBlock)() = ^{
NewScreenController *vc = [[NewScreenController alloc] init];
[self presentViewController:vc animated:YES completion:nil];
};
[HUD showAnimated:YES
whileExecutingBlock:executionBlock
completionBlock:completionBlock];
}

UIRefreshControl incorrect title offset during first run and sometimes title missing

The text is offset wrong by the first launch of UIRefreshControl... later sometimes the refresh text doesn't show up at all and just the spiny is visible
I don't think i had this issue with iOS6... might be related to iOS7
Is in a UITableViewController added as a child to a VC, which resides in a modal presented UINavigationController
- (void)viewDidLoad {
[super viewDidLoad];
[self setRefreshControlText:#"Getting registration data"];
[self.refreshControl beginRefreshing];
}
- (void)setRefreshControlText:(NSString *)text {
UIFont * font = [UIFont fontWithName:#"Helvetica-Light" size:10.0];
NSDictionary *attributes = #{NSFontAttributeName:font, NSForegroundColorAttributeName : [UIColor blackColor]};
self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:text attributes:attributes];
}
This is definitely an iOS 7 bug, but I haven't figured out exactly what caused it. It appears to have something to do with the view hierarchy — adding my UITableViewController as a child view to a wrapper view controller appeared to fix it for me at first, although the bug is back since iOS 7 GM.
It looks like adding the following code to your UITableViewController after creating the refresh view fixes the positioning issue for good:
dispatch_async(dispatch_get_main_queue(), ^{
[self.refreshControl beginRefreshing];
[self.refreshControl endRefreshing];
});
calling endRefreshing under viewWillAppear did it for me:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.refreshControl endRefreshing];
}
Under iOS7 with a custom UITableViewController inside a UINavigationController
I had the same problem and for me it worked with layoutIfNeeded after setting the attributedTitle:
- (void)setRefreshControlText:(NSString *)text
{
UIColor *fg = [UIColor colorWithWhite:0.4 alpha:1.0];
NSDictionary *attrsDictionary = #{NSForegroundColorAttributeName: fg};
self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:text attributes:attrsDictionary];
[self.refreshControl layoutIfNeeded];
}
Cédric suggested to use [self.refreshControl setNeedsLayout], but this does not force an immediate update of the view, so you must use layoutIfNeeded.
I finally found the holy grail on this, which looks working in all cases
note : UIRefreshControl is added to a UITableViewController (note, never add UIRefreshControl just as subview to a normal UIVIewController's UITableView) (best to add UITableViewController as a child VC inside a UIViewController if you must)
note : that this also fixes the problem, that the UIRefreshControl is not vissible at first refresh (link)
Add to you .h
#interface MyViewController ()
#property (nonatomic, assign) BOOL refreshControlFixApplied;
- (void)beginRefreshing;
- (void)beginRefreshingWithText:(NSString *)text;
- (void)endRefreshing;
- (void)endRefreshingWithText:(NSString *)text;
#end
Add to you .m
////////////////////////////////////////////////////////////////////////
#pragma mark - UIRefreshControl Fix (peter#min60.com) https://stackoverflow.com/questions/19121276/uirefreshcontrol-incorrect-title-offset-during-first-run-and-sometimes-title-mis/
////////////////////////////////////////////////////////////////////////
- (void)beginRefreshingWithText:(NSString *)text {
[self setRefreshControlText:text];
[self beginRefreshing];
}
- (void)endRefreshingWithText:(NSString *)text {
[self setRefreshControlText:text];
[self.refreshControl endRefreshing];
}
- (void)beginRefreshing {
if (self.refreshControl == nil) {
return;
}
if (!self.refreshControlFixApplied) {
dispatch_async(dispatch_get_main_queue(), ^{
if ([self.refreshControl.attributedTitle length] == 0) {
[self setRefreshControlText:#" "];
}
[self.refreshControl beginRefreshing];
dispatch_async(dispatch_get_main_queue(), ^{
[self.refreshControl endRefreshing];
dispatch_async(dispatch_get_main_queue(), ^{
// set the title before calling beginRefreshing
if ([self.refreshControl.attributedTitle length] == 0) {
[self setRefreshControlText:#" "];
}
if (self.tableView.contentOffset.y == 0) {
self.tableView.contentOffset = CGPointMake(0, -self.refreshControl.frame.size.height);
}
[self.refreshControl beginRefreshing];
self.refreshControlFixApplied = YES;
});
});
});
} else {
if (self.tableView.contentOffset.y == 0) {
self.tableView.contentOffset = CGPointMake(0, -self.refreshControl.frame.size.height);
}
[self.refreshControl beginRefreshing];
}
}
- (void)endRefreshing {
if (self.refreshControl == nil) {
return;
}
if (!self.refreshControlFixApplied) {
dispatch_async(dispatch_get_main_queue(), ^{
[self endRefreshing];
});
} else {
if (self.tableView.contentOffset.y < 0) {
self.tableView.contentOffset = CGPointMake(0, 0);
}
[self.refreshControl endRefreshing];
}
}
- (void)setRefreshControlText:(NSString *)text {
UIFont * font = [UIFont fontWithName:#"Helvetica-Light" size:10.0];
NSDictionary *attributes = #{NSFontAttributeName : font, NSForegroundColorAttributeName : [UIColor colorWithHex:0x00B92E]};
self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:text attributes:attributes];
}
Use only methods
- (void)beginRefreshing;
- (void)beginRefreshingWithText:(NSString *)text;
- (void)endRefreshing;
- (void)endRefreshingWithText:(NSString *)text;
UIRefreshControl seems to still be broken on IOS9.3 when you change the attributedTitle while the tableView is pulled down. What seems to work is to subclass UIRefreshControl and force update its layout once the (attributed) title is changed.
The core fix is to trigger a change to the tableView contentOffset (causing some hidden magic in the _update method which layouts the spinner and text subviews) and additionally forcing the frame height to its expected value ensuring the background color fills up the pulled down region.
#implementation MEIRefreshControl
{
__weak UITableView* _tableView;
}
- (instancetype)initWithTableView:(UITableView*)tableView
{
self = [super initWithFrame:CGRectZero];
if (self)
{
_tableView = tableView;
}
return self;
}
#synthesize title = _title;
- (void)setTitle:(NSString *)title
{
if (!PWEqualObjects(_title, title))
{
_title = title;
self.attributedTitle = [[NSAttributedString alloc] initWithString:_title ? _title : #""];
[self forceUpdateLayout];
}
}
- (void)forceUpdateLayout
{
CGPoint contentOffset = _tableView.contentOffset;
_tableView.contentOffset = CGPointZero;
_tableView.contentOffset = contentOffset;
CGRect frame = self.frame;
frame.size.height = -contentOffset.y;
self.frame = frame;
}
#end
This is the code that seems to fix all the issues. Many of the others that involved beginning or ending refreshing where interfering with other parts of the control.
//This chunk of code is needed to fix an iOS 7 bug with UIRefreshControls
static BOOL refreshLoadedOnce = NO;
if (!refreshLoadedOnce) {
__weak typeof(self) weakself = self;
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^(void){
self.tableView.contentOffset = CGPointMake(0, -weakself.refreshControl.frame.size.height);
} completion:^(BOOL finished) {
weakself.refreshControl.attributedTitle = self.refreshControl.attributedTitle;
[weakself.refreshControl setNeedsUpdateConstraints];
[weakself.refreshControl setNeedsLayout];
refreshLoadedOnce = YES;
}];
}
//End of bug fix
I had the same problem, I did solve it by setting attributed text with space string to refresh control directly after init refresh control
_refreshControl = [[UIRefreshControl alloc]init];
[_refreshControl setAttributedTitle:[[NSAttributedString alloc]initWithString:#" "]];
After that, setting new attributed text to refresh control was without any problems.
[[self refreshControl] setAttributedTitle:[[NSAttributedString alloc]initWithString:[NSString stringWithFormat:#"Последнее обновление: %#", [dateFormat stringFromDate:[_post dateUpdated]]]]];
UPDATE
I noticed that problem come back when I use attrsDictionary:
this code works fine
NSAttributedString* attributedString = [[NSAttributedString alloc]initWithString:string];
[[self refreshControl] setAttributedTitle: attributedString];
and this make refreshControl's title appear directly after view loaded
NSAttributedString* attributedString = [[NSAttributedString alloc]initWithString:string attributes:attrsDictionary];
[[self refreshControl] setAttributedTitle: attributedString];
I didn't find solution yet.
UPDATE
Finally found solution, after refreshcontrol init set attributed string also with attributes:attrsDictionary
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:[UIColor appDarkGray], [UIFont fontWithName:#"OpenSans-CondensedLight" size:14.0f], nil] forKeys:
[NSArray arrayWithObjects:NSForegroundColorAttributeName, NSFontAttributeName, nil]];
[_refreshControl setAttributedTitle:[[NSAttributedString alloc]initWithString:#" " attributes:attrsDictionary]];
so after that there is no problem to set new refreshcontrol's title.
The solution for me was to set a text in viewDidAppear, no need to call
beginRefreshing or endRefreshing on the mainQueue
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"d MMM, HH:mm"];
NSString *lastUpdated = [NSString stringWithFormat:NSLocalizedString(#"refresh_last_updated", nil),[formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[[[DatabaseController sharedInstance] getCurrentSettings].lastTimeStamp doubleValue]]]];
UIFont *font = [UIFont fontWithName:FONT_LATO_LIGHT size:12.0f];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:lastUpdated attributes:#{NSFontAttributeName:font}];
_refreshControl.attributedTitle = attrString;
}

Animate Spinner when loading new page

I have a UITableView which from an external RSS feed.
When you select a row it uses navigationController and slides in from the right, the problem is that the RSS feed contains images therefore it can can take a few seconds to load and without any indication of what is going on you can mistake it for an application crash.
I decided to add a spinner so that you know that new page is loading.
Here is my code:
RootViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"Loading New Page");
[tableView deselectRowAtIndexPath:indexPath animated:YES];
DetailsViewController *detailViewController = [[DetailsViewController alloc] initWithNibName:#"DetailsViewController" bundle:nil];
detailViewController.item = [rssItems objectAtIndex:floor(indexPath.row/2)];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = CGPointMake(160, 240);
[self.view addSubview:spinner];
[spinner startAnimating];
[spinner release];
}
DetailsViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
NSString *imgURL = [item objectForKey:#"image"];
NSData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imgURL]];
item_photo.image = [[UIImage alloc] initWithData:mydata];
item_title.text = [item objectForKey:#"title"];
item_date.text = [NSString stringWithFormat:#"Date: %#",[item objectForKey:#"date"]];
item_time.text = [NSString stringWithFormat:#"Time: %#",[item objectForKey:#"time"]];
item_cost.text = [NSString stringWithFormat:#"Cost: £%#",[item objectForKey:#"cost"]];
item_info.text = [item objectForKey:#"description"];
self.navigationItem.title = #"Event Type";
}
There are two problems with this code.
The Spinner does not active until after the new page has loaded.
The Spinner does not disable once loaded.
If anyone could help me with this problem i would be truly gratefully.
You are adding the activity indicator view to the view of the controller which is pushing the detail view controller, so you wont see it anyway
try moving the second group of code to the viewDidLoad method of DetailsViewController, you can call stopAnimating on the activity indicator when you are finished loading. To get a reference to the UIActivityIndicator you should add a tag
e.g. in viewDidLoad
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = CGPointMake(160, 240);
spinner.tag = 12;
[self.view addSubview:spinner];
[spinner startAnimating];
[spinner release];
in the loadingFinished method (whichever method is called when finished loading)
[[self.view viewWithTag:12] stopAnimating];
You need to do some work in a background thread. If the following line is the one that takes the time:
detailViewController.item = [rssItems objectAtIndex:floor(indexPath.row/2)];
Then you could do this in the background with GCD:
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
// This is the operation that blocks the main thread, so we execute it in a background thread
id item = [rssItems objectAtIndex:floor(indexPath.row/2)];
// UIKit calls need to be made on the main thread, so re-dispatch there
dispatch_async(dispatch_get_main_queue(), ^{
detailViewController.item = item;
[spinner stopAnimating];
});
});
And +1 to #wattson12 - you need to add the spinner to the new view instead. Alternatively you could add the spinner to the current view, and instead put the pushViewControllercall into your GCD main-queue block.
Final point - you'll want to remove the spinner from its superview once you stop it animating. Alternatively, you can have a single instance of the spinner, and set hidesWhenStopped to YES.
This is a spinning wheel over a blurred view in swift:
func blurScence(){
let blurEffect: UIBlurEffect = UIBlurEffect(style: .Dark)
let blurView: UIVisualEffectView = UIVisualEffectView(effect: blurEffect)
blurView.translatesAutoresizingMaskIntoConstraints = false
blurView.frame = self.view.frame
let spinner = UIActivityIndicatorView(activityIndicatorStyle:.White)
spinner.center=blurView.center
blurView.addSubview(spinner)
spinner.startAnimating()
self.view.addSubview(blurView)
}

MPMoviePlayerController controls when opened in a UIModalPresentationFormSheet style modal and the user makes the video fullscreen

In my iPad app, I have a UIButton that is calling an IBAction to call a view controller as a modal to show a video in. I wanted the modal to appear as 720x405, and that part seems to work out okay. Here is the IBAction code the button is executing:
-(IBAction)videoPlayerTest:(id)sender {
VideoModalViewController *vc = [[VideoModalViewController alloc] initWithNibName: #"VideoModalViewController" bundle: nil];
vc.fileName = #"testvideo.m4v";
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:vc animated: YES];
vc.view.superview.frame = CGRectMake(0, 0, 720, 405);
vc.view.superview.center = self.view.center;
[vc release];
}
The modal comes up where I want it, and the controls respond on the MPMoviePlayerController; the jog bar, pause, play, etc. but if the user taps on the fullscreen button, the video does go fullscreen alright, but after that the MPMoviePlayerController won't respond to any subsequent taps on the player controls. If I remove the modalPresentationStyle line it will work, but the modal appears on a fullscreen view instead of the 720x405 modal like I want. I've added Observers to try resizing the frame and recenter it when the user makes the movie controller fullscreen and back to windowed, but it didn't appear to help at all. Here is that code.
- (void)willEnterFullscreen:(NSNotification*)notification {
NSLog(#"willEnterFullscreen");
[self setModalPresentationStyle:UIModalPresentationFullScreen];
self.view.frame = CGRectMake(0, 0, 1024, 768);
self.view.center = self.view.center;
}
- (void)willExitFullscreen:(NSNotification*)notification {
NSLog(#"willExitFullscreen");
[self setModalPresentationStyle:UIModalPresentationFormSheet];
self.view.frame = CGRectMake(0, 0, 720, 405);
self.view.center = self.view.center;
}
- (void)playMovie {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
NSString *videoString = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(0, 0, 720, 405);
moviePlayer.view.backgroundColor = [UIColor grayColor];
[moviePlayer prepareToPlay];
[moviePlayer play];
}
This is my first post-- hope I did it right and provided enough information about the problem I'm having.
I've solved my problem. I was unaware of MPMoviePlayerViewController and I created that and used that as my modal instead. It works great.
-(void)playVideo:(NSString *)fileName {
NSString *videoString = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self presentModalViewController:mpViewController animated:NO];
[[mpViewController moviePlayer] play];
}
-(IBAction)videoPlayerTest:(id)sender {
[self playVideo:#"testvideo.m4v"];
}
Thought I'd post what I came up with just in case somebody else encounters the same

Show activity indicator during application launch

I am trying to add an activity indicator during startup. I did have a launch image, but I'd rather have just an indicator alone. I added the following to my app delegate, but the indicator doesn't appear.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// *******Create activity indicator****
UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(225, 115, 30, 30)];
[activity setBackgroundColor:[UIColor clearColor]];
[activity setActivityIndicatorViewStyle: UIActivityIndicatorViewStyleGray];
[window addSubview: activity];
[activity release];
[activity startAnimating];
activity.hidden = FALSE;
// *******End activity indicator****
MainViewController *viewController = [[MainViewController alloc] initWithNibName:#"MainView" bundle:nil];
self.mainViewController = viewController;
[window addSubview:[mainViewController view]];
mainViewController.view.frame = CGRectMake(0, 20, 320, 411);
[window addSubview:[rootController view]];
[window makeKeyAndVisible];
#if !TARGET_IPHONE_SIMULATOR
[application registerForRemoteNotificationTypes:
UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
#endif
application.applicationIconBadgeNumber = 0;
// Hide indicator
[viewController release];
activity.hidden = TRUE;
[activity stopAnimating];
return YES;
}
I visited this question from back in 2009, but the solution didn't work for me.
iPhone-SDK:Activity Indicator during Startup?
For all those who needed this, and i know there were many...
(Made on Xcode version 4.2.1)
So...
In the AppDelegate.h add this:
#property (nonatomic, strong) UIImageView *splashView;
In the AppDelegate.m add this:
On the top of the page of cours #synthesize splashView;
And then:
- (void) splashFade
{
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
splashView.image = [UIImage imageNamed:#"Default.png"];
[_window addSubview:splashView];
[_window bringSubviewToFront:splashView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationDelay:2.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(startupAnimationDone:finished:context:)];
splashView.alpha = 0.0;
[UIView commitAnimations];
//Create and add the Activity Indicator to splashView
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.alpha = 1.0;
activityIndicator.center = CGPointMake(160, 360);
activityIndicator.hidesWhenStopped = NO;
[splashView addSubview:activityIndicator];
[activityIndicator startAnimating];
}
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[splashView removeFromSuperview];
}
The [UIView setAnimationDelay:2.5] is responsible for how long the splashView will be in front by the delay time you choose.
You can change the position of the indicator by changing the nubmers of x/y in:
activityIndicator.center = CGPointMake(160, 360);
At last, under the methode:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Just add this:
[self performSelector:#selector(splashFade) withObject:nil];
And there you go :)
Hope it helped.
Have a nice programming....
I don't think this is possible from looking at the docs for UIApplicationDelegate
The earliest your app is called is in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Which as the name suggests is when your app hasFinishedLaunching
The reason nothing happens when you show and hide the indicator is to do with threading. The user interface will only update at the end of your method where the net result of your changes will be that the indicator is hidden.
Another solution is to let the launchimage load and when your ViewController loads at the viewDidLoad, use overlay + indicator on top of your view with alpha below 1:
UIView *baseView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.view addSubview:baseView];
[baseView setBackgroundColor:[UIColor blackColor]];
baseView.userInteractionEnabled = NO;
baseView.alpha = 0.4;
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
indicator.center = self.view.center;
[self.view addSubview:indicator];
[indicator bringSubviewToFront:self.view];
[indicator startAnimating];
Now comes the fun part, use delegate to remove the indicator + overlay when all your background threads finish to load up and simple call a method via your delegate:
- (void) onFinishLoading{
[indicator stopAnimating];
[baseView removeFromSuperview];
}
In order to stopAnimation and removeFromSuperView you might want to make baseView and indicator property + #synthesize
This isn't possible (as #Paul.S is saying). However, you can simulate this by adding a (static, so it's not animating) Default.png-splash-screen to your project.
In my opinion, though, you should rather invest in a better performance. For example: do you link your app with unused frameworks (eg. QuartzCore, MapKit) or something.
Starting an app should take 2 seconds max. At this time, you don't really need to show your user an activity-indicator. If it does take longer, you should take a look at what makes it so slow, rather than trying to hide it.