loading a view on top of tabbarcontroller - iphone

I have a tabbar controller and on touching a button in one of view's navigation right button i want to load a (nav controller + view )on top of it. The view which is on the top of it is semi transparent and i should be able to see the content in the tabbar controller.
I tried using the [self.tabbarcontroller.view addSubview:navController];
I worked perfectly and it is working fine. But when i tried to do the same thing in landscape view it is just occupying half the screen. what should be done ? is there a way to fix this issue
can i use the window to load my new view ? will it occupy the entire screen ? i tried autoresize masks and there is no effect

What is the bounds of the navController/tabbarcontroller? Are you setting correctly to that of the window?
You can output it easily:
NSLog(#"navController bounds: %#",NSStringFromCGRect(navController.view.bounds));

Do you mean addSubview:navController.view? I didn't think you could treat view controllers as views.
In general, you need to be careful when using UIViewController outside of the framework-managed classes. UIKit automatically handles stuff like viewWillAppear/autorotation for the view controllers that it knows about, but it doesn't know about the VCs whose views you randomly add as subviews.
EDIT: If all you require is that it appears to be transparent, you can use something like
UIGraphicsBeginImageContextWithOptions(tabBarController.view.size, 0, 0);
[tabBarController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
and then use img as the view background. It won't animate the stuff in the background, but provided you don't need this, it's much faster than having lots of transparent views stacked on top of each other.

Related

How to add an image view sharing between navigation bar and view?

I had to add an image so that half of it is in the navigation bar and remaining is in the view.I know there is always a probability of adding two images,but i want to know is there any way to add an image view(only one)between the two?Now i know i can do this way ,
[self.navigationController.navigationBar addSubview:imageView];
and also self.view addSubview:imageView,but i need a single image view to be shared between the two
ie the first half is in navigation bar and the remaning is in the view.can anybody help me on this?
No, this is not possible AFAIK. A view (including a UIImageView) can only have one superview. SO it's either a child of the UINavigationBar or one of the other view, but not both.
with ios 7 you can use translucent navigations bars so that you can set the imageview in your view and it shines through the navbar :-)

Transparency for top UIView not working

In a UINavigationController I have a UITableView. I use a settings-button to allow users changing some table settings.
When the settings-button is tapped I push a new view onto the navigation stack.
This new view has the following view structure
-> UIView1 411 x 320 px (backgroundColor supposed to be transparent) !!!!
-->> UIView2 270 x 300 px (backgroundColor grey)
--->>> Screen elements
My problem is that I want UIView1 to be transparent so that the information behind is still visible. All my attempts, such as
setting the bg color to transparent
changing the alpha value
removing the Opaque indicator
have failed so far.
Any clues? most appreciated!
UINavigationController is not designed to allow "buried" view controllers to still be showing under the current visible view controller. (The iOS framework can actually unload the views of view controllers on the nav stack that aren't the current top item!)
So if you try to do it, it just won't work, or you'll have problems. (Same goes for modal view controllers on the iPhone -- even if you make the background transparent, the view you're pushing on top of will disappear.)
If you really want the old UI to still be visible underneath, consider presenting your new entire UI as a UIView placed over the current view (i.e. do [existingView addSubview:myNewView]).

UITableview changing height when shown from different UINavigationControllers ('More')

I'm having an issue with UITableViewController's tableView changing its frame position when presented from a UITabBarController, within a UINavigationController. The frame is fine when displayed from a regular tab. However, if I move and show the UITableViewController from the 'More' Section, the tableview moves down the same height as the navigation bar (which I don't want it to). When I tested the runtime frame coordinates between proper and nonproper positions, it shows as the same (0.0, 0.0, 320.0, 411.0).
This issue only happens AFTER I've shown the tableView in one Nav Controller and then it's moved and shown in another, like the 'More' VC to the tab, or tab to the 'More' VC
What's going on here and how can I fix this?
The last image is how it looks like when the app launch, as it should be, with he table view right below the nav bar. In the first two however, you can see that the tableview has been moved down.
Thanks in advance!
I was able to solve the issue. It turns out that when you move a UITableView controller within a UINavigationController to the moreNavigationController, 44 pixels are added to the 'top' variables of contentInset and scrollIndicatorInsets. I'm not sure why this is happening or why those 44 pixels aren't being removed when the tableView leaves the 'moreNavigationController', but here's the answer. I'm calling these two lines from within viewWillAppear.
self.tableView.contentInset = UIEdgeInsetsMake(44.0, 0.0, 0.0, 0.0);
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(44.0, 0.0, 0.0, 0.0);
The UITableViewController has this behaviour that it always try to best fit the screen size. UITableViewController is perfect for fullscreen tableview but otherwize I recommend not using the UITableViewController but instead implement a tableViewControler yourself by implementing both the datasource and delegate. Some did set resizeSubViews to NO and solve their problem but I really advice recreate the controller yourself which is not that much work.
Reset autosizing property of table view nib file.
You can find it inside :
Tool>Attribute Inspector
First take a UITableView in the view using XIB. Then add navigation bar and resize the tableview. You will get what do you actually want.
If you still find any problem then please let me know.
If you can display your code, or take a screenshot of your setup, it would be a lot easier. From my experience, creating UITableViewController instances and hooking them up in Interface Builder will expand to fill the screen.
How are you connecting it to the "More" tab? If it's in two tabs, and you're doing ANYTHING dynamic, check your UITableViewController class viewDidLoad method. You shouldn't have to add / delete / re-add the table unless they're separate instances.
Some places to check:
NSLog your tableHeaderView height and position
NSLog your tableFooterView height and position
Create a backgroundView and assign it to the tableView's backgroundView property to see what it's true dimensions are and where it's being displayed
Check where the UITableViewController's view starting position is.
Wish I could help more. Would like to see your setup / code.

Custom size app screen on iPad

I am trying to create a mid-size screen for my app on iPad.
In didFinishLaunchingWithOptions(), I do this:
CGRect winRect = CGRectMake(100,100,500,500);
navController.view.frame = winRect;
the screen comes up fine and I can click around and do stuff until the orientation changes. It takes the screen to original full size - how can I make it stick to my winRect frame? I tried setting the parentViewController.view.frame/view.frame to winRect in willRotateToInterfaceOrientation() but no good.
Any ideas?
Thanks.
Generally, you shouldn't mess with the frame of a view controller's view. View controllers tend to resize their views on many occasions, for example when toolbars and navigation bars are hidden or made visible or when the interface orientation changes.
For custom-sized views, create a separate view, set its frame to your custom size and add it as a subview to your view controller's view.

Resizing UITableView on RootController

Is it possible to resize the UITableView on the RootController of a nav based app? When RootViewController.xib is opened in IB, there isn't a view. Just the UITableView. Clicking the inspector and then the little yellow ruler, frame height is grayed out. I'm adding a toolbar programmatically to the RootViewController:
[toolbar setFrame:rectArea];
That works fine but the bottom cell in the tableview is partially hidden because the tableview doesn't know about the toolbar.
The easiest way, is to adjust the contentInset (which is inherited from UIScrollView). Resizing by setting the frame can cause crazy drawing bugs in cells.
For example, if you are trying to resize a tableview for the keyboard, do something like this:
tableView.contentInset = UIEdgeInsetsMake(0.0, 0.0, 216.0, 0.0);
tableView.scrollIndicatorInsets = tableView.contentInset;
Hope that helps someone. This way worked best for me.
Yes, but you need to have a ViewController (not a UITableViewController) as the root controller for the nav, and wrap the actual UITableView in the UIViewControllers view.
You can still have the UIViewController conform to the UITableViewDelgate and Datasource protocols, and use all the same methods you have now in your UITableViewController.
P.S. you'll get more responses if you use the plain "iphone" tag.
You could also just set the Content and Scroller inset of the tableview
I encountered a similar issue when attempting to display the detail controller by itself, see: http://vimeo.com/13054813
The issue is that the SplitView controller applies its own transform to the sub-controllers, taking them out of the orientation detection loop, which blows goats and seems incredibly 'hackish' for built-in classes. (The video illustrates what happens when you make the detail view the root view, then add it back to the split view and make the split view root while in landscape; you get double rotation of the detail view.)
Unfortunately I've again run into these transformation issues while attempting to resize a SplitViewController's detail sub-view in response to the keyboard appearing/disappearing. In portrait, all works fine, in landscape it's fscked.
Yes, adjust the contentInset and scrollIndicatorInsets are the convenient way to resize the UITableView.
As the answer of Sam Soffes posted, I succeed resize UITableView in UITableViewController for the bottom UIToolbar.