Is it possible to dim the entire iPhone screen while keeping one view on top? - iphone

I have a UITabbar-based iphone app with a NavigationController bar on the top. I also have a logout view that I present on top, while dimming the background. You can see here: http://d.pr/i/XH6x
However, the dimmed background does not cover the UINavigationBar on top nor the UITabbar on the bottom. How can I dim the entire screen, while keeping the LogoutView on top?
Right now, I'm doing the dimmed view with this code:
UIView *dimView = [[UIView alloc] initWithFrame:self.collectionView.frame];
dimView.tag = kDimView;
dimView.backgroundColor = [UIColor blackColor];
dimView.alpha = 0.7;
[self.view addSubview:dimView];
Thank you!
EDIT: I should mention that this is a UITabBarController based application, with UInavigationControllers for each of the 3 tabs.

try this.
UIWindow* mainWindow = [[UIApplication sharedApplication] keyWindow];
dimView.frame = CGRectMake(00, 00,mainWindow.frame.size.width , mainWindow.frame.size.height);
Hope this will help you.

You have to dim the view, where your tabbar and navigation bar lies.
For example, there is one UIViewController named RootViewController, which contains your UITabbarController and UINavigationController.
So try to set alpha value for that view, and then do add subview normally, as you are doing.

Related

Tab Bar controller is not accessible

I have created a tab based application for iphone. when the 1st tab presses a first view will present. this view contains a button, on pressing it another view loads.
Code is:
-(IBAction)buttonPressed: (id) sender
{
Cities *cv=[[Cities alloc] initWithNibName:#"Cities" bundle:nil];
cv.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:cv animated:YES];
[cv release];
}
Now problem is that this view is loading in whole screen so that I am not able to access tab bar.
I have set the frame for this view and the view is loading in this frame,
-(void)viewWillAppear:(BOOL)animated
{
self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, 400);
}
but in remaining part white screen is appearing means tab bar is not accessible.
I want that whatever will be load at any time tab bar should be always accessible.
Please help me out.
Add
cv.modalPresentationStyle = UIModalPresentationCurrentContext;
Have you tried using UINavigationController inside your tabbar to dig inside your UIViewControllers??
for Ref : Adding NavigationController to Tabbar
do you really need a viewController Class for what you are trying to display??
if der's no core functionality being used, i think it will be much easier with UIView.
Happy Coding :)

Why there is no separate line under Navigation bar?

I have a concern about the separate line under navigation bar. Please take a look at below screenshot
At the "Overview Settings" screen, I implement UITableViewController, and I see the separate line appear natively. But at "Overview" screen, I implement UIViewController and this line is not appear. How do I make it appear on every screen without add a customized view to fake this line?
Thanks so much!
Its because What I think is that the above one is navigation bar and below one is tabbar.
Kindly cross check it once again.
Or try changing the tint color of the navigation bar and check whehter its working or not.
hAPPY cODING...
After researching, I found a best way to do this is add an UIView as a subview of UINavigationBar as following code:
CGRect navFrame = [navBar bounds];
UIView *separateLine = [[UIView alloc] initWithFrame:CGRectMake(0, navFrame.size.height - 2, navFrame.size.width, 1)];
separateLine.backgroundColor = RGB(38,38,38);
separateLine.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[navBar addSubview:separateLine];
[separateLine release];

Navigation bar and top margin

I have an issue with a UINavigationBar and its y-offset. The bar is displayed without a UINavigationController as superview, yet that should not matter. In the viewController where the navigation bar appears the setup looks like this:
// Add Basic View
CGRect viewFrame = [[UIScreen mainScreen] applicationFrame];
UIView *myView = [[UIView alloc] initWithFrame:viewFrame];
myView.backgroundColor = [UIColor greenColor];
self.view = myView;
[myView release];
UINavigationBar *myBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
.... add some Stuff to the bar...
[self.view addSubview:myBar];
[myBar release];
As I add the navigationBar as a chield View to self.view I assumed that origin.y = 0 would mean that the bar should get directly displayed below the status bar. This works as expected if I start the app on my iPad, rotate it once (or more) and then drill down to the view that is described above. In this case the UINavigationBar is displayed properly. Yet if I start my app and directly drill down to the controller described above (without rotating the device before this particular controller appears) the navigation bar slides 20 points below the status bar. But as soon as I rotate the device then, the bar is fine again. I have checked the viewFrame.origin.y value and it is 20 points in both situations, hence I do not understand why in one case the bar just seems to ignore the origin.y value of its superview but does not in the other.
I am really confused about this, has anybody else ever experienced such an issue?
Thanks a lot for your help!
Ps. I have also tried it with a UIToolbar, the problem is the same.
Yes. My solution is to set the "Full screen on launch" flag to on in Interface Builder for the window in the MainWindow-iPad.xib file. Then design your views as if the 20 pixel status bar were always displayed, so in my root view, I have a toolbar that is positioned 20px below the top of the screen in the content view.

How to make a view which covers whe whole screen, including the status bar?

I want to make an overlay which is partially transparent, and covers the entire screen including the status bar. I've seen that the folks at tapbots do exactly that. So it must be possible somehow. Status bar should still be visible!
Before iPhoneOS 3.2:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
after iPhoneOS 3.2:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationNone];
For more information on these, see the documentation for UIApplication.
There are two ways to hide the status bar:
Programaticaly at runtime by using UIApplication sharedApplication:
- (void)setStatusBarHidden:(BOOL)hiddenwithAnimation:(UIStatusBarAnimation_)animation
Or at design time using the Info.plist property UIStatusBarHidden yes/no value.
You could try creating a full-size view and adding it as a subview of your main window. Something like:
CGRect mainWindowSize = [UIScreen mainScreen].bounds;
UIView* overlay = [[UIView alloc] initWithFrame:mainWindowSize];
// Use colorWithRed:green:blue:alpha: or a solid color then manually tweak alpha
overlay.backgroundColor = [UIColor redColor];
overlay.alpha = 0.2; // transparency level
overlay.userInteractionEnabled = YES;
// Add it on top of the main window
UIWindow* mainWindow = (((MyAppDelegate*)
[UIApplication sharedApplication].delegate).window);
[mainWindow addSubview:overlay];
Caveats: You may have to manually hide the status bar. Also, this overlay view and its subviews are going to get all the user tap events. May want to make sure that's what you want.
push the view controller as a modalViewController....
if your view controller is AVC and assuming you use a navigation controller:
[self presentModalViewController:AVC animated:YES];
from the current view controller you're on.

iPhone Modal View Smaller that the screen

I'm trying to do something that shouldn't be that complicated, but I can't figure it out.
I have a UIViewController displaying a UITableView. I want to present a context menu when the user press on a row. I want this to be a semi-transparent view with labels and buttons.
I could use an AlertView, but I want full control on the format of the labels and buttons and will like to use Interface Builder.
So I created my small view 250x290, set the alpha to .75 and create a view controller with the outlets to handle the different user events.
Now I want to present it.
If I use presentModalViewController two (undesired) things happen
1) the view covers all of the screen (but the status bar).
2) It is semi-transparent, but what I see "behind" it its not the parent view but the applications root view.
Ive tried adding it as a subview, but nothing happens, so Im not doing something right:
RestaurantContextVC* modalViewController = [[[RestaurantContextVC alloc] initWithNibName:#"RestaurantContextView" bundle:nil] autorelease];
[self.view addSubview:modalViewController.view];
Is it possible to do what I want?
Thanks in advance.
Gonso
I'm coding similar thing. My approach include.....
Not using dismissModalViewControllerAnimated and presentModalViewController:animated.
Design a customized full sized view in IB. In its viewDidLoad message body, set the background color to clearColor, so that space on the view not covered by controllers are transparent.
I put a UIImageView under the controllers of the floating view. The UIImageView contains a photoshoped image, which has rounded corners and the background is set to transparent. This image view serves as the container.
I uses CoreAnimation to present/dismiss the floating view in the modal view style: (the FloatingViewController.m)
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor clearColor]];
[UIView beginAnimations:nil context:nil];
[self.view setFrame:CGRectMake(0, 480, 320, 480)];
[UIView setAnimationDuration:0.75f];
[self.view setFrame:CGRectMake(0, 0, 320, 480)];
[UIView commitAnimations];
}
wangii
Thats pretty much the solution I found.
I load the view with loadNibNamed and then just add it on top with addSubView, like this:
//Show a view on top of current view with a wait indicator. This prevents all user interactions.
-(void) showWaitView{
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:#"WaitView" owner:self options:nil];
#ifdef __IPHONE_2_1
waitView = [ nibViews objectAtIndex: 0];
#else
waitView = [ nibViews objectAtIndex: 1];
#endif
CGFloat x = self.view.center.x - (waitView.frame.size.width / 2);
CGFloat y = self.view.center.y - (waitView.frame.size.height / 2);
[waitView setFrame:CGRectMake(x,y,waitView.bounds.size.width,waitView.bounds.size.height)];
[self.view addSubview:waitView];
}
Could you elaborate on points 3 and 4?
What I did to give the view the round rect aspect is put it inside a round rect button.
This code will actually allow you to have a small floating view, but if the view is smaller that its parent, the user could interact with the visible part of the parent.
In the end I create my view with the same size, but kept the code just in case.
Gonso
I would strongly consider using a navigation controller to slide in your subview instead of overlaying it. This is the expected model and any small benefit you may think you'll get by doing it your own way will be greatly offset by the principle of (least) surprise.
If you really really have to do it this way, I believe the trick is to add the first table view as a subview of a transparent "holding" view that the view controller maintains. Then add your new sub view as another subview of that.
Again, if you really want to do this, instead of adding a transparent "holding" view, since this pop-up is essentially modal, I would make it a subview directly of the window.
You might want to put in a transparent black shield behind it to prevent touches on the background and focus input on the popup.
But seriously, consider either popping a controller on the stack or using that alert view. Unless you've hired a $$ designer, it's probably not going to look appropriate on the iPhone.
What I did was create a UIViewController on top of my UINavigation controller in my app delegate and made it a property of a singleton object for convenience:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//--- create root navigation controller
self.window.rootViewController = self.navigationController;
//--- create view controller for popups:
popupViewController = [[BaseViewController alloc] init];
popupViewController.view.backgroundColor = [UIColor clearColor];
popupViewController.view.hidden = true; //for rendering optimisation
[self.window addSubview:popupViewController.view];
[AppState sharedInstance].popupViewController = self.popupViewController;
//--- make all visible:
[self.window makeKeyAndVisible];
return YES;
}
At any point in my app, I can then call e.g.
MyViewController * myVC = [[UIViewController alloc] init];
//... set up viewcontroller and its view...
// add the view of the created view controller to the popup view:
[AppState sharedInstance].popupViewController.view.hidden = false;
[[AppState sharedInstance].popupViewController.view addSubview:myVC.view];
The BaseViewController used on the top just inherits from UIViewController and sets up a full-screen view:
//----- in BaseViewController implementation
- (void)loadView {
//------- create root view:
CGRect frame = [[AppState sharedInstance] getScreenFrame];
rootView = [[VCView alloc] initWithFrame:frame];
rootView.backgroundColor = [UIColor whiteColor];
self.view = rootView;
}