UISplitView with SingleViewController - iphone

How do I add UISplitView after clicking on the SingleView application? Clearly when the user has successfully logged in then they will see splitView? How is it possible? Please give me guidelines or if possible then code for that because I'm new to iPhone development and I haven't more knowledge for it?

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1.90];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.navigationController.view cache:YES];
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
if (!masternavigationController) {
masternavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
}
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
if (!splitViewController) {
splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:masternavigationController, detailViewController, nil];
UIViewController *view_controller = (UIViewController *)[navigationController.viewControllers objectAtIndex:([navigationController.viewControllers count]-1)];
[masternavigationController.navigationBar setHidden:TRUE];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
[splitViewController.view setBounds:CGRectMake(0, 0, 1024, 748)];
[splitViewController.view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
[view_controller.view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
view_controller.view.tag = 17;
[UIView animateWithDuration:1.05 animations:^{navigationController.view.alpha = 0.0;} completion:^(BOOL finished){
[navigationController.view addSubview:splitViewController.view];
[UIView animateWithDuration:1.00 animations:^{navigationController.view.alpha = 1.0;} completion:nil];}];
rootview *rtview = [[rootview alloc] initWithNibName:#"rootview" bundle:nil];
rtview.delegate = detailViewController;
[detailViewController.view addSubview:rtview.view];
flag = YES;
[rtview release];
}
[UIView commitAnimations];
// [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:#selector(doneAnimation) userInfo:nil repeats:NO];
[masterViewController release];
[detailViewController release];
This is how we have to add splitview controler you have to check the condition weather you are logged in or not and then call this in a method

Related

The tabBarController is not displayed

i want to make tabbarcontroller programatically. The tabBarController is not displayed in the page. can anyone tell that whts going wrong.and can we make more than one tabbarcontroller in an application
ViewController.m
- (void)viewDidLoad
{
report=[[UIViewController alloc]initWithNibName:#"ViewController" bundle:nil];
View1 *template=[[View1 alloc]initWithNibName:#"View1" bundle:nil];
View2 *acc=[[View2 alloc]initWithNibName:#"View2" bundle:nil];
View3 *four=[[View3 alloc]initWithNibName:#"View3" bundle:nil];
View4 *five=[[View4 alloc]initWithNibName:#"View4" bundle:nil];
nav1=[[UINavigationController alloc]initWithRootViewController:report];
nav2=[[UINavigationController alloc]initWithRootViewController:template];
nav3=[[UINavigationController alloc]initWithRootViewController: acc];
nav4=[[UINavigationController alloc]initWithRootViewController:four];
nav5=[[UINavigationController alloc]initWithRootViewController:five];
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:#"Title" image:[UIImage imageNamed:#"singleicon.png"] tag:0];
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:#"Reports" image:[UIImage imageNamed:#"doubleicon.png"] tag:1];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:#" New " image:[UIImage imageNamed:#"clockicon.png"] tag:2];
UITabBarItem *item3=[[UITabBarItem alloc]initWithTitle:#"four" image:[UIImage imageNamed:#"dependenticon.png"] tag:3];
UITabBarItem *item4=[[UITabBarItem alloc]initWithTitle:#"five" image:[UIImage imageNamed:#"toolicon.png"] tag:4];
nav1.tabBarItem = item;
nav2.tabBarItem = item1;
nav3.tabBarItem = item2;
nav4.tabBarItem=item3;
nav5.tabBarItem=item4;
//[item1 setBadge:#"25"];
self.tabBarController=[[UITabBarController alloc]init];
[self.tabBarController setViewControllers:[NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nav5,nil]];
self.report = self.tabBarController;
// [self.report makeKeyAndVisible];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
Use below code:
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nav5,nil]];
self.window.rootViewController = self.tabBarController;
UPDATE:
also for Hide and Show the UITabBar then use bellow code ..
just put this methods in AppDelegate.m file and when you want to hide tabbar at that time just create AppDelegate object and call bellow hideTabBar method
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
int height = 480;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x,view.frame.origin.y, 320, 436)];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
int height = 436;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
}
}
[UIView commitAnimations];
}
put all the coding in the action of the button and push the tabBarController like that:-
[self.navigationController pushViewController:tabBarController animated:YES];
If you want to add UITabBarController programmatically, then you need to add your tabbarcontroller to your ViewController. you need to use this line,
[self.view addSubview:self.tabBarController.view];
You need to add tabBarController in view you have missed the one line
i just did this
[self.navigationController pushViewController:tabBarController animated:YES];

Animated Splash Screen in iPhone

I need to implement animated splash screen to the iPhone application. I have seen skype application where same thing is already implemented.
Can anyone has idea how can i implement same thing in my applicatio
You can use sequence of images, here is code :
for(NSInteger i=1;i<=totalImages;i++){
NSString *strImage = [NSString stringWithFormat:#"Activity_%d",i];
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:strImage ofType:#"png"]];
[imageArray addObject:image];
}
splashImageView.animationImages = imageArray;
splashImageView.animationDuration = 0.8;
and just call startAnimation and endAnimation method of UIImageView.
OR
Its very simple...I had used it in to begin my app with splashView.Hope it vil help you.... In AppDelegate.m:
application didFinishLaunchingWithOptions:
UIImage* image=[UIImage imageNamed:#"splash.jpg"];
splashView=[[UIImageView alloc]initWithImage:image];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[self performSelector:#selector(removeSplash) withObject:self afterDelay:2];
[window makeKeyAndVisible];
To remove splashView:
-(void)removeSplash{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:YES];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[splashView removeFromSuperview];
[UIView commitAnimations];
[window addSubview:viewController.view];
}
We can show a .gif image in webView and it looks perfect!
Take a new UIViewController class named SplashView with XIB and then add an UIWebView with (320.0, 480.0) frame, hidden statusbar also.
In SplashView.h
#import <UIKit/UIKit.h>
#interface SplashView : UIViewController
#property(nonatomic, retain)IBOutlet UIWebView *webView;
#end
In SplashView.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *imagePath = [[NSBundle mainBundle] pathForResource: #"animated" ofType: #"gif"];
NSData *data = [NSData dataWithContentsOfFile:imagePath];
[self.webView setUserInteractionEnabled:NO];
[self.webView loadData:data MIMEType:#"image/gif" textEncodingName:nil baseURL:nil];
}
This is about SplashView class. Now come to your appdelegate's class.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
splashView = [[SplashView alloc]initWithNibName:#"SplashView" bundle:nil];
[self.window addSubview:splashView.view];
[self performSelector:#selector(changeView) withObject:nil afterDelay:3.0];
[self.window makeKeyAndVisible];
return YES;
}
-(void)changeView
{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[splashView.view removeFromSuperview];
[self.window setRootViewController:self.viewController];
}
Take a UIView & an Imageview into it. Give all your images to ImageView to animate.
-(void)viewDidLoad
{
NSArray *arrImage=[NSArray arrayWithObjects:
[UIImage imageNamed:#"1.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
nil];
imgVw.backgroundColor=[UIColor purpleColor];
imgVw.animationImages=arrImage;
imgVw.animationDuration=2.5;
imgVw.animationRepeatCount=1;
[imgVw startAnimating];
[NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:#selector(animateNext) userInfo:nil repeats:NO];
}
This will show up you application icon.
After that you will show the controls those would be hidden by default and animate them from bottom to up.
-(void)animateNext
{
lbl.hidden = NO;
btn.hidden = NO;
txt1.hidden = NO;
txt2.hidden = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.9];
lbl.frame=CGRectMake(lbl.frame.origin.x,lbl.frame.origin.y - 150,lbl.frame.size.width,lbl.frame.size.height);
imgVw.frame = CGRectMake(imgVw.frame.origin.x, imgVw.frame.origin.y - 150, imgVw.frame.size.width, imgVw.frame.size.height);
txt1.frame = CGRectMake(txt1.frame.origin.x, txt1.frame.origin.y - 150, txt1.frame.size.width, txt1.frame.size.height);
txt2.frame = CGRectMake(txt2.frame.origin.x, txt2.frame.origin.y - 150, txt2.frame.size.width, txt2.frame.size.height);
btn.frame = CGRectMake(btn.frame.origin.x, btn.frame.origin.y - 150, btn.frame.size.width, btn.frame.size.height);
[UIView commitAnimations];
}
Hope this help...
Try this
Appdelegate.h
#interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UIImageView *splashView;
}
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ViewController *viewController;
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
// Make this interesting.
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
splashView.image = [UIImage imageNamed:#"Default.png"];
[self.window addSubview:splashView];
[self.window bringSubviewToFront:splashView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(startupAnimationDone:finished:context:)];
splashView.alpha = 0.0;
splashView.frame = CGRectMake(-60, -85, 440, 635);
[UIView commitAnimations];
return YES;
}
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[splashView removeFromSuperview];
}
you need to start your app with a viewcontroller,with an uiimageview in it..Create a series of .png images to be subjected to the UIImageView check how to animate array of images in uiimageview. Further to dismiss it once animation over you would need to implement a protocol that will inform your starting first viewcontroller of your app to dismiss the animation
- (void) welcomeScreen
{
//Welcome Screen
UIImageView* welcome = [[[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)]autorelease];
welcome.image = [UIImage imageNamed:#"img.png"];
[window addSubview:welcome];
[window bringSubviewToFront:welcome];
//Animation Effects (zoom and fade)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
[UIView setAnimationDelegate:welcome];
[UIView setAnimationDidStopSelector:#selector(removeFromSuperview)];
//set transparency to 0.0
welcome.alpha = 0.0;
//zoom effect
welcome.frame = CGRectMake(-60, -60, 440, 600);
[UIView commitAnimations];
}
yes simple in AppDelegate class first defile imageview like bellow..
#interface AppDelegate : UIResponder
{
UIImageView *splashView;
}
and in .m file...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageNamed:#"Default"];
[self.window addSubview:splashView];
[self performSelector:#selector(loadViewIphone) withObject:nil afterDelay:2.0];
}
[self.window makeKeyAndVisible];
return YES;
}
-(void)loadViewIphone
{
[splashView removeFromSuperview];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:#"transitionViewAnimation"];
}
i hope this help you..
:)

display subviews with delay

When this action gets executed it displays secondviewcontroller directly what i want is that viewcontroller displays first and after 40 or 50 secs it displays secondviewcontroller next and so on.
- (void)displayviewsAction:(id)sender
{
PageOneViewController *viewController = [[PageOneViewController alloc] init];
viewController.view.frame = CGRectMake(0, 0, 320, 480);
SecondViewController *secondController = [[SecondViewController alloc] init];
secondController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
[self.view addSubview:secondController.view];
[self.view bringSubviewToFront:viewController.view];
[self.view addSubview:toolbar];
[self.view sendSubviewToBack:viewController.view];
[self.view addSubview:toolbar];
}
Anyone have any ideas how i can do that.
Try making the view invisible and then quickly fading it in after 40 seconds have passed.
secondController.view.alpha = 0.0;
[self.view addSubview:secondController.view];
[UIView animateWithDuration:0.5
delay:40
options:UIViewAnimationCurveEaseInOut
animations:^{
secondController.view.alpha = 1.0;
}
completion:NULL
];
you can add the secondViewController in a separate method and call that method using performSelector:withObject:afterDelay
- (void)displayviewsAction:(id)sender {
PageOneViewController *viewController = [[PageOneViewController alloc] init];
viewController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
[self performSelector:#selector(secondViewController) withObject:nil afterDelay:40];
}
-(void)secondViewController {
SecondViewController *secondController = [[SecondViewController alloc] init];
secondController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:secondController.view];
}
An alternative/addition to the method detailed by Aravindhanarviless is to use an NSTimer:
self.myTimer = [NSTimer scheduledTimerWithTimeInterval:40 target:self selector:#selector(showSecondViewController) userInfo:nil repeats:NO];

Switching View through a function

I'm working on an iPhone/iPad application and trying to switch views through a function call, not by a button. I've seen lots of sources switching views triggered by a button, but there's nothing that explains how to switch views triggered by a function. I tried to do this on my own, but it failed. Here's the code that I tried:
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.webview == nil) {
self.webview = [[MainViewController alloc] init];
/* webview initialized with storyboard */
if (self.view.superview == nil) {
[self.view insertSubview:self.webview.view atIndex:0];
}
[storyboard release];
}
}
This is viewDidLoad of the viewController.m. First, it shows WebView.
- (void)changeView {
self.normview = [[AlternateViewController alloc] init];
/* normview initialized with storyboard */
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self.webview viewWillDisappear:YES];
[self.webview viewDidDisappear:YES];
[self.webview.view removeFromSuperview];
[self.view insertSubview:self.normview.view atIndex:0];
[self.normview viewWillAppear:YES];
[self.normview viewDidAppear:YES];
[UIView commitAnimations];
}
And when this changeView function (in a viewController.m) is called, It should change the view from webview to normview (actually, it works fine when the same code is triggered by a button). But when I call this function in other file (not viewController.m), such as
ViewController *viewcontroller = [[ViewController alloc] init];
[viewcontroller changeView];
It doesn't work. Anyone can give a clue to solve this or an alternative way? (ps. I'm testing on iPad.)
You can switch views with this function:
YourView *screen = [[YourView alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
[screen release];
You can set the modaltransitionstyle to your willings.
Don't forget to import your headerfile at the top of your class.
#import "YourView.h"

UITableView Navigation Bar "Flickers" on Animation

I have a UIViewController, a "switcher" that will basically just rotate a view from one to another.
It all works great, except that the view that I am transitioning to is a UIViewController which holds a UITableViewController. For some reason, when the animation "flips", the navigation bar is invisible, and once the animation completes the navigation bar just appears.
It really doesn't look good and I was wondering if anyone knew why I might be seeing this and how I could fix it?
Thanks,
--d
EDIT: Adding some code by request!
Switcher viewDidLoad method - Currently Initializing both of the ViewControllers because I thought it may help
[super viewDidLoad];
LogoView *logoController = [[LogoView alloc] init];
self.logoView = logoController;
[self.view insertSubview:logoView.view atIndex:0];
[logoController release];
MainController *vController = [[MainController alloc] init];
self.controller = vController;
[vController release];
switchTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(switchViews) userInfo:nil repeats:NO];
Switcher switchViews method
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (self.controller.view.superview == nil)
{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[controller viewWillAppear:YES];
[logoView viewWillDisappear:YES];
[logoView.view removeFromSuperview];
[self.view insertSubview:controller.view atIndex:0];
[logoView viewDidDisappear:YES];
[controller viewDidAppear:YES];
}
[UIView commitAnimations];
MainController viewDidLoad method
CGRect frame = CGRectMake(0, 0, 320, 410);
FirstLevelController *controller = [[FirstLevelController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:controller];
navController.view.frame = frame;
navController.navigationBar.tintColor = [UIColor blackColor];
[controller release];
[self.view addSubview:navController.view];
Inside the FirstLevelController I just add the items to the table view... I've tried adding a navController.title = #"Home", but I am not even seeing the black navbar without text... it's just a big empty space.
Help is muchly appreciated!
Hah! I changed the animation "cache" from YES to NO, and it fixed it! Yay!