I have created an app that contain two Xib file one for iPhone 4 And one for iPhone5. iphone 5 screen look ok but in iphone 4 it will different.
Here is the xib file for iPhone 4
And here is the simulator screen.
My xib file size is 320*460. i dont have idea about this behavior. can any one plz help.
UPDATE
I am presenting my VC using this code
TransactionDetailViewController * transactionDetailViewController;
//select the zib according to the screen size
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
transactionDetailViewController = [[TransactionDetailViewController alloc] initWithNibName:#"TransactionDetailViewController" bundle:nil];
} else {
transactionDetailViewController = [[TransactionDetailViewController alloc] initWithNibName:#"TransactionDetailViewController_iPhone4" bundle:nil];
}
// Pass the selected object to the new view controller.
self.navigationController.navigationBar.tintColor = [UIColor redColor];
[self.navigationController pushViewController:transactionDetailViewController animated:YES];
You are loading iPhone 5 nib both the time. take a isIpad global flag set it depending upon the device then use this init method in your view controller
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
NSString *nibName=nil;
nibName=isiPad?#"viewController_iPhone5":#"viewController";// isIpad is flag set if device is iPhone5
self = [super initWithNibName:nibName bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
The iPhone 4 screen is not resizing or scaling correctly and therefore some of the content is behind the tab bar.
The standard size for the tab bar is 49 high and the nav bar is 44 high. You could resize the view to be 320 x 367 as this is 460 - 49 - 44.
This is not the best solution admittedly but it may just work
Related
I am attempting to use both storyboards for my iOS project, but I cannot get the code to switch to the appropriate storyboards. Instead, the code does absolutely nothing. Is it that I do not have a setting set correctly that controls the switch? The main storyboard for devices not of the iPhone 5, is called MainStoryboard. The iphone 5 appropriate layout is called iphone5. I'm thinking this may be a project configuration setting issue. (This is in my appdelegate.m file).
-(void)initializeStoryBoardBasedOnScreenSize {
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{ // The iOS device = iPhone or iPod Touch
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if (iOSDeviceScreenSize.height == 480)
{ // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured)
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [iPhone35Storyboard instantiateInitialViewController];
// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Set the initial view controller to be the root view controller of the window object
self.window.rootViewController = initialViewController;
// Set the window object to be the key window and show it
[self.window makeKeyAndVisible];
}
if (iOSDeviceScreenSize.height == 568)
{ // iPhone 5 and iPod Touch 5th generation: 4 inch screen (diagonally measured)
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:#"iphone5" bundle:nil];
// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController];
// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Set the initial view controller to be the root view controller of the window object
self.window.rootViewController = initialViewController;
// Set the window object to be the key window and show it
[self.window makeKeyAndVisible];
}
} else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{ // The iOS device = iPad
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
}
}
I suggest just using 1 storyboard for handling the iPhone 5 vs iPhone 3-4S screen sizes.
When your Storyboard is open, there is a button at the bottom that toggles between the 2 sizes-- you can see in real-time how things will look.
The button is to the left of the Zoom in % Zoom out buttons in the bottom right corner, and looks like this:
To handle how your object's frame & position will be affected by the screen size change-- you need to set the autosizing properties for each object in your view. You can do this by selecting an object, and in the right Inspector panel, Select the Size inspector like so:
You see those red lines in the Autosizing box? Play around with them to see how they will effect your object. The inner ones relate to the size (if the width, or height stretches), and the outer ones relate to the position.
I'm not sure about your apps layout but from experience you will probably have to mess with the inner vertical line (how the height will change), and the bottom line (you want that to stay near the bottom).
The more you mess around with each the more you will see what each does.
I am getting a height of 656 in my viewDidAppear on a view controller. This is not the correct height that I am expecting from an iPhone 5. Any idea why this might be happening? I have a UIView that I added as a subview of this UIViewController and I set the struts such that it will always stick to the bottom of the UIViewController. However because the height is 656, I can no longer see this UIView. ANy idea why?
Here's my code:
- (void) viewDidAppear:(BOOL) animated
{
[super viewDidAppear:animated];
NSLog(#"%f", self.view.bounds.size.height);
}
This is how I am initializing the VC:
SavedViewController *savedStoriesVC = [[SavedViewController alloc] initWithNibName:#"SavedViewController" bundle:nil];
savedStoriesVC.managedObjectContext = managedObjectContext;
savedStoriesVC.delegate = self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:savedStoriesVC];
navController.navigationBarHidden = YES;
I just had this same problem. I was able to "fix" it by turning off all of the struts and springs. But then, of course, rotations didn't work.
I have a UITabbar having 5 tabs like this
Now I want to hide the UITabbar when taps on the Feed Tab. I want to show the full screen there. I am able to hide the tabbar but the UIView of Feed screen is not adjusting itself and I can see the white space at the place of UITabBar. I set the frame of view after hiding the UITabbar but it is also not working. How can I get the object of UITabbarController in the UIViewController classes which are added on the UITabbar so that I can call the delegate methods of UITabbarController. For instance, how can I have the object of UITabbarController in Feed Class.Please Help! If I am not clear please let me know.
Thanks-
Adding to Ariel answer, you need to set "hidesBottomBarWhenPushed" property to YES,when you are loading it from the nib.
As " initWithCoder"-Method is called if you are loading from the nib, you need to set that property there only.
Hope this will help you out.
Try to add self.hidesBottomBarWhenPushed = YES; inside of -(id)initWithCoder:(NSCoder *)aDecoder; of the Feed class implementation like so:
-(id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if(self){
self.hidesBottomBarWhenPushed = YES;
//more of your initialization code...
}
return self;
}
It should be in -(id)initWithCoder:(NSCoder *)aDecoder; and not -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil; as your view is loaded from the .xib file by the application.
Try to set self.navigationController.view.frame size when you hide the tabbar.
You can get the fullscreen size with [[UIScreen mainScreen] bounds].
My iphone application is showing strange behavior when rotating: a gap appears between the navigation title and content view inside a tab bar view (details on how to reproduce are below). I've created a tiny test case that exhibits the same problem: a custom root UIViewController, which creates and displays a UITabBarController programmatically, which has two tabs: 1) plain UIViewController, and 2) UINavigationController created programmatically with a single plain UIViewController content view.
The complete code for the application is in the root controller's viewDidLoad (every "*VC" class is a totally vanilla UIViewController subclass with XIB for user interface from XCode, with only the view background color changed to clearly identify each view, nothing else).
Here's the viewDidLoad code, and the shouldAutorotateToInterfaceOrientation code, this code is the entire application basically:
- (void)viewDidLoad {
[super viewDidLoad];
FirstVC *fvc = [[FirstVC alloc] initWithNibName:#"FirstVC" bundle:nil];
NavContentsVC *ncvc = [[NavContentsVC alloc] initWithNibName:#"NavContentsVC" bundle:nil];
UINavigationController *svc = [[UINavigationController alloc] initWithRootViewController:ncvc];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:2];
[localControllersArray addObject:fvc];
[localControllersArray addObject:svc];
fvc.title = #"FirstVC-Title";
ncvc.title = #"NavContents-Title";
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.view.frame = CGRectMake(0, 0, 320, 460);
[tbc setViewControllers:localControllersArray];
[self.view addSubview:tbc.view];
[localControllersArray release];
[ncvc release];
[svc release];
[fvc release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
Here's how to reproduce the problem:
1) start application
2) rotate device (happens in simulator, too) to landscape (UITabBar properly rotates)
3) click on tab 2
4) rotate device to portrait -- notice gap of root view controller's background color of about 10 pixels high beneath the Navigation title bar and the Navigation content view.
5) click tab 1
6) click tab 2
And the gap is gone! From my real application, I see that the gap remains during all VC push and pops while the NavigationController tab is active. Switching away to a different tab and back to the Nav tab clears up the gap.
What am I doing wrong? I'm running on SDK 3.1.3, this happens both on the simulator and on the device. Except for this particular sequence, everything seems to work fine. Help!
This problem occurs when you nest a UINavigationController within another UIViewController (in this case a UITabBarController). If you had the UINavigationController as the root view controller, then this problem wouldn't occur.
One solution may be to go in and alter the frame of the navigation bar (set the y origin from 0 to 20), but the documentation states explicitly not to do this. So to me, this is an indication that it isn't considered good UI to nest a UINavigationController - you shouldn't be doing it.
Please let me know what you think - thanks. :)
A workaround works in some occasion:
After rotating, force a refresh of the NavigationBar and therefore the frame of its view is resized properly. Some code like this:
(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
// if _navigationController is showing
[_navigationController setNavigationBarHidden:YES];
[_navigationController setNavigationBarHidden:NO];
}
Here is my problem:
- I have one navcontroller and inside it one tabbar controller with 4 view controller.
- I want to add following functionality:
- On landscapeRight to dismiss navcontroller, tabbar controller and everything and load whole new controller - this one goes ok, here is the code:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
// Just delete the lines for the orientations you don't want to support
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
[appDelegate ToHorizontalAverageResponseView:self];
}
return YES;
}
Here is the code in the App Delegate:
- (void)ToHorizontalAverageResponseView:(id)sender
{
HorizontalResponseViewController *tempController = [[HorizontalResponseViewController alloc] initWithNibName:nil bundle:nil];
[self setHorizontalResponseViewController: tempController];
[tempController release];
//[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
// View rotation transformation
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation( M_PI * 90.0 / 180.0 );
[[horizontalResponseViewController view] setTransform:landscapeTransform];
[window addSubview:[horizontalResponseViewController view]];
}
The question is how to transfer back to portrait view and all those navbar and tabbar controllers?
Thx,
Mladen
It sounds like you are trying to build something along the lines of the iPod-CoverFlow transition. The question (on how to build the coverflow effect) was asked in Stanford's CS193P lecture and the answer hinted in the following direction:
If you can afford the memory overhead, it may be the best thing to add a new landscape view on top of all the portait views (not discarding them as you suggest). The user then interacts with this landscape view as desired until going back to portrait. All this time, the portrait views remained quietly in the background.