Add a Subview to Splashscreen - iphone

I am currently trying to add a Activity Indicator View to my Splashscreen. It only should appear once - at the first start of the App. Some images are created that are needed for the App, but it takes some time.
While the images are created, the Splashscreen is still visible. So I thought it could maybe be possible to add a Activity Indicator as a Subview of the Splashscreen or at least add it somehow over the Splashscreen.
Is there a possibility to make this possible?
Thanks for your help in advance.

You will need to add the "Splashscreen" as top most view to your window, the "splashcreen" it self is not a view. The system wil just display the default.png:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
splashScreen = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, -20.0f, 320.0f, 480.0f)];
splashScreen.backgroundColor = [UIColor blackColor];
splashScreen.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Default" ofType:#"png"]];
[self.window addSubview:splashScreen];
[self.window makeKeyAndVisible];
[self performSelector:#selector(applicationDidStart) withObject:nil afterDelay:0.1];
return YES;
}
splashScreen is a class variable, you could add an Activity Indicator to the splashView.
Then in the applicationDidStart did start methods place the code that will take some time:
- (void) applicationDidStart {
// some thing that takes a while
[splashScreen removeFromSuperView];
[splashScreen release], splashScreen = nil;
}

I dont think it is possible to add a subview to the Splash Screen.
There is a workaround where in you can push an intermediate view on applicationDidFinishLaunching and have the background image of the view as same as that of the splash screen.
Now you can do the stuff where your images are created on this view.
Once images are created, Call a method in applicationDelegate which will pop the intermediate view and add your regular view.
Hope this helps you.

Related

Switch from ViewController to TabBarController

I have one small problem. I have iOS app in xcode and when I launch it, it comes with
TabBarController. But then, I need to go to another ViewController (there would be some
info with pictures) and after that, I need go back to main page with TabbarController, but
when I click to back button, It show up without Tabbar on the bottom... For more clear, I've made a scheme...
Click to this link to show image scheme
Can anybody slove this please? Im working without storyboards, so I need it
programmatically. Thank you for every reply!
Steve
My guess is that your window.rootViewController is actually your UINavigationController. If you want the TabBar be present in all the screens then you need to make it your window.rootViewController.
Set it in your app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[[NSBundle mainBundle] loadNibNamed:#"TabBarController" owner:self options:nil];
self.window.rootViewController = tbc;
return YES;
}
Create a xib with a tabcontroller, drop a navigation controller inside tab bar.
Set the Class of the Viewcontroller and the nib name.
Inside the method of the Button, needs to be like:
- (IBAction)go:(id)sender
{
Primeiro2ViewController *p2vc = [[Primeiro2ViewController alloc] initWithNibName:#"Primeiro2ViewController" bundle:nil];
p2vc.title = #"Primeiro 2";
[self.navigationController pushViewController:p2vc animated:YES];
self.navigationController.navigationBar.tintColor = [UIColor greenColor];
}
If you need a sample, I upload for you later.

last Button of actionsheet does not get clicked

I have used an actionsheet in my project and when it appears it show all buttons but last (4th) button does not responds to my click(only it's half part responds)..
I know the reason it is because i have used a TabBarController and the present class is inside that tabbar controller....
only that part of the actionsheet is responding which is above the tabs....and my last button is half above and half is on top of tabbar
please help
i suggest using this:
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
I had the same problem that you have and using this method to show it worked for me. The TabBar wants to stay key Window what makes your bottom button appear above, but is actually under the tabbar.
Hope this does the trick for you..
Edit
If you use landscape mode and the method above doesn't work. You can use the following fix:
#Vinh Tran: [sheet showFromTabBar:self.parentViewController.tabBarController.tabBar]
What method do you use to show your actionsheet. Try showFromTabBar: method
The real problem comes in, when your interface is rotated to landscape and the parent view controller has a transformation on it. Believe me, that's a realistic scenario, doh. Then the action sheet is clipped and you can't use the parentViewController because it is transformed. The solution to avoid all these issues is to create a new window, add a rotatable view controller as rootViewController and use its view to display the sheet.
CGRect applicationRect = [[UIScreen mainScreen] bounds];
UIWindow* actionSheetWindow = [[UIWindow alloc] initWithFrame:applicationRect];
RotationViewController* rootViewController = [[RotationViewController alloc] initWithNibName:nil bundle:nil];
actionSheetWindow.rootViewController = rootViewController;
[rootViewController release];
actionSheetWindow.hidden = NO;
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil];
[actionSheet setCancelButtonWithTitle:#"Cancel" handler:^{
actionSheetWindow.hidden = YES;
[actionSheetWindow release];
}];
[actionSheet showInView:rootViewController.view];
The code above uses BlocksKit, but you can do it also by using the actionSheet delegate and instance properties.
RotationViewController is just a UIViewController subclass that implements
- (void) viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
self.view.opaque = NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}

Show a view as a splash screen in didFinishLaunchingWithOptions

I have a Tab Bar Application and I want to simply display a view (splash screen) once the didFinishLaunchingWithOptions method loads up the tab bar controller. Why is this so hard? Please show me how I'd load up and show a Xib file called SplashView.xib below and display it:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the tab bar controller's view to the window and display.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
// Load up and show splash screen Xib here
return YES;
}
First thing I'd mention is that splash screens are specifically frowned upon in the HIG. Especially ones that only serve to make the user wait & stare at some logo they don't care about.
Now that rant is out of the way, I'll assume that you probably have some loading going on that you'd like to have happen before the tabs are displayed.
In this case I don't load up a tab bar in the MainWindow.xib. Instead I launch my single view (with XIB) that does the loading. The reason is this: You'll pay for the loading of all of those views before you can even see your splash screen.
In the case of loading data, sometimes these tabs depend on this data being loaded, so it makes more sense to wait to load up the tab bar controller.
The app delegate ends up looking like this:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window makeKeyAndVisible];
[window addSubview:splashController.view]; //this assumes MainWindow.xib defines your splash screen, otherwise....
UIViewController *splashController = [[SplashController alloc] initWithNibName:#"SplashController" bundle:nil];
splashController.delegate = self;
[window addSubview:splashController.view];
//hang on to it in an ivar, remember to release in the dealloc
}
Then in the splash screen controller, when I'm done loading, I do this:
-(void)doneLoading {
[self.delegate performSelector:#selector(splashScreenDidFinishLoading)];
}
Of course self.delegate doesn't exist, and it can be added simply like this:
//header
#property (nonatomic, assign) id delegate;
//implementation
#synthesize delegate;
Then just make sure and implement that method on the app delegate:
-(void)splashScreenDidFinishLoading {
//load up tab bar from nib & display on window
//dispose of splash screen controller
}
I've used this pattern in a handful of apps and is simple and works well. You could also choose to do a nice transition animation in the method above.
Hope this helps.
In your app delegate's header file:
#interface AppDelegate {
...
IBOutlet UIView *splash; // add this line
}
In IB open the SplashView.xib, set the File Owner's class to the class of your app delegate, connect the splash outlet. Add this to show a splash view:
[[NSBundle mainBundle] loadNibNamed: #"SplashView" owner: self options: nil];
[window addSubview: splash];
You will possibly want to hide the splash view too:
[splash removeFromSuperview];
[splash release];
splash = nil;
You could use UIView animation block to fade out the splash view to be extra-cool. That said, splash screens are evil.
I think the app delegate is indeed a better place for this kind of stuff.
I would do something like:
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"Splash.png"]];
[imageView setCenter:CGPointMake(240, 160)];
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:imageView];
[imageView retain];
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self //display for 3 secs
selector:#selector(continueLoadingWhatever:)
userInfo:nil
repeats:NO];
And then...
- (void)continueLoadingWhatever:(id)sender {
//do whatever comes after here
}
I probably wouldn't do this in the app delegate, but in the root view controller. You should never have to add anything unnecessary directly to the window, especially if it contains interaction (I know this doesn't).

Circumvent screenshot for iOS 4

I would like to clear a view before an application is switched away from, to change the launch image so that the next time the app is entered it will not display some insecure data.
iOS 4 provides applicationDidEnterBackground and applicationWillResignActive...however, neither of these seem to be able to prevent the screenshot from being taken before I have a chance to clear the view.
-applicationDidEnterBackground does get called before the screenshot. Turns out I was simply hiding my view improperly.
A simple way to clear the view was to set the hidden property on my UIView.
Just to add a snippet of code for a fast solution to this problem using a full background image declared on the initialization and hiding it.
You can do a more sofisticated hide of the particular contents of each view by registering to the notification, and in the views hide the particular views (labels) you want to hide.
Another solution is to check which viewcontroller is showing and switch between differente screenshots of the view of this viewcontroller without the data shown.
The easiest way:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIImageView *backgroundView_ = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Default.png"]];
self.backgroundView = backgroundView_;
[backgroundView_ release];
// Add other controllers views
// ...
[self.window bringSubviewToFront:self.backgroundView];
self.backgroundView.hidden = YES;
[self.window makeKeyAndVisible];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
self.backgroundView.hidden = YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
self.backgroundView.hidden = NO;
}

Adding logo for iPhone app

I want to add a logo view as iPhone application lunch. I code as follows
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
UIImage image = [[UIImage alloc] imageWithContentsOfFile:#"1.jpg"];
UIImageView view = [[UIImageView alloc] initWithImage:image];
[window addSubViews:view];
[NSThread sleepForIntervalTime:10];
[view removeFromSubview];
[window addSubview: navigationController.view];
[window makeKeyAndVisible];
}
But simulator can't display as I want.just display navigationController's view.
I think the reason is iPhone render the first view after "applicationDidFinishLaunching"
Are there other solutions about that?
Just add the image you want to be the LOGO to your project with the name: Default.png
It will automatically become the startup screen for your application.
Your approach won't work. applicationDidFinishLaunching delegate runs after all the loading was done. Besides, delaying it for 10 seconds won't be accurate since application might load faster on some devices than others.
Pablo is right - you can just use the Default.png for this.
However, your code will never work for two reasons.
1)
The main thread of the application is the UI thread - the one responsible for dealing with updating the interface and this is the thread that is running your applicationDidFinishLaunching:.
If you just call [NSThread sleepForIntervalTime:10] the thread will sleep. However, this also means that while the thread is sleeping, the UI won't get updated. Then, when you call [view removeFromSuperview] it will remove the image and carry on. You will never get to see the image!
To get your code to work you should do something like this :
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[window addSubview: navigationController.view];
UIImage *image = [UIImage imageWithContentsOfFile:#"1.jpg"];
UIImageView *view = [[UIImageView alloc] initWithImage:image];
[window addSubView:view];
[view release];
[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:#selector(removeImage:) userInfo:view repeats:NO];
[window makeKeyAndVisible];
}
- (void) removeImage:(NSTimer *)timer {
UIImageView *view = (UIImageView *)timer.userInfo;
[view removeFromSuperview];
}
This code will show an image for 10 seconds and then remove it. However, if you just want an image at launch, using Default.png is definately the way to do it!
2)
You have added the navigator view infront of your image - in the code above, I have moved adding the navigator's view to be before the UIImage. This means that the image will be infront of the navigator for the 10 second delay until it is removed, revealing the navigator view.
Hope this helps,
Sam