A toolbar is not where it should be - iphone

I have an iPhone app. i'm trying to make it universal w/out new xibs. from a UI aspect, my app is fairly simple and straight forward, i just have a a UIImageview and some toolbars.
i'm having an issue where i set my top toolbar to 0, 0 but it is appearing in the middle of my screen when its an iPad.
topToolBar.frame = CGRectMake(0, (-1 * topToolBar.frame.size.height), topToolBar.frame.size.width, topToolBar.frame.size.height);
i initially hide the toolbar and show it if you tap the screen (works properly on iPhone). when i try to set the toolbar hidden on the iPad, its in the middle of the screen. when i nslog the frame, it shows (0, -44, 320, 44) which means it still thinks the screen size is iphone of (480, 320).
the funny part is when i use my tap function to show/hide the toolbar, it behaves properly with a frame of (0, -44, 768, 44).
my hide/show animation block is:
[UIView animateWithDuration:.2
delay:0
options:(UIViewAnimationOptionAllowUserInteraction)
animations:^{
topToolBar.frame = CGRectMake(0, (-1 * topToolBar.frame.size.height), topToolBar.frame.size.width, topToolBar.frame.size.height);
}
completion:nil];
its the same code i use to try to initially hide the toolbar. any ideas what is going on?

I would guess it’s an issue with the toolbar’s autoresizing mask. If you’re creating it in Interface Builder, make sure that the strut on the bottom is grayed out and that the ones on the other three sides are highlighted, like this:
If you’re creating the toolbar programmatically, you can just set its autoresizingMask to UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin.

Related

Weird sizing issue with UIPickerView

I am experiencing some strange behavior with a UIPickerView that I animate on to the screen. Interface Builder tells me the size of a UIPickerView is 216.0, but when I animate the view on to the screen using
[UIView animateWithDuration:0.25 animations:^{
pickerView.frame = CGRectMake(0, self.view.frame.size.height-216, 320, 216);
}];
The picker view actually only comes partway on to the screen. To get the entire picker view, I need to treat the height as if it is 280. What could cause this?
280 is the same as 216+64. 64 is sum of a 20pt status bar plus a 44pt nav or toolbar. I would check your hierarchy, perhaps, you add the picker to the app window, but set coordinates using your VC's view frame, which is inside another container?

I rotate screen manually to Landscape but the taskbar buttons dont use the new full width of 480, rather they only use the 320 portion of the bar

I rotate my screen to landscape mode
- (void)rotateScreen
{
[self.tabBarController.view setTransform:landscapeTransform];
self.tabBarController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
self.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 480.0, 320.0);
self.tabBarController.view.center = CGPointMake (240.0, 160.0);
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
}
It all seems to work well,
The view and Navbar are rotated, the postion of the Tabbar changes position to the bottom of the screen.
The problem is that the buttons on the Tabbar do not use the full width of the screen rather they only use the space of 320pixles rather than growing onto the full width of the bar, which has become 480 pixels now.
Is there someway I can ask it to grow in width?
I have seen similar issues when the views you have added are added as subviews using the addSubView method instead of being pushed to the navigation bar.
That is the first thing I would review.
Did you anchor the tab bar to the right edge of the view? The anchors play an important role in sizing you view based on the parent.
Read about UIViewAutoResizingMask in developer documentation for more info.

UIScrollView height adjusts from IB

I've created a UIScrollView in Interface Builder which takes up the entire screen of the iPad (0, 0, 1024, 768)
However - when running the app, the scrollView is only displaying on the screen at (0, 0, 1024, 440). The 440 is an estimate, but it is not extending all the way down to fill the screen as it should.
I've done this same thing in other apps and have not encountered this issue.
I've run "Clean" on the project and I've tried deleting the scrollView and recreating it and still the same issue occurs.
I even tried to programmatically reinforce what's in Interface Builder but still it showed up the same way.
CGRect scrollFrame = CGRectMake(0, 0, 1024, 768);
[scrollView setFrame:scrollFrame];
If you have any idea why this may be happening, your help would be GREATLY appreciated.
* UPDATE *
After some more research, there is something wrong with the view controller.
That area at the bottom where the scrollView isn't showing is totally not accessible. If I put a button toward the bottom of the screen, I can't click that button. If it's up in the top half of the screen I can click it just fine.
Also, the scrollview isn't really starting at 0, 0. Where it starts it is missing the top part of the content. So it seems like the scrollView DOES have the height of 768, but is starting at -320 so that the top of it is off the top of the screen and the bottom of it ends before the bottom of the screen.
The issue seems to have been that the app thought it was in Portrait mode even though I had the .xib in Landscape mode.
Fixed it with this little trick in the viewDidLoad of the mainProjectViewController:
CGRect landFrame = self.view.frame;
landFrame.size.width = self.view.frame.size.height;
landFrame.size.height = self.view.frame.size.width;
self.view.frame = landFrame;
Actually, viewing it in landscape mode is just a convenience for you to see what happens if you rotate the device. Launching in landscape mode can be problematic. See this question and its answers for some excellent info.

How To Present Half Screen Modal View?

I have a UIViewController and when a button is pressed, I want a half screen view to slide up with a UIPicker in it.
I made a UIView in IB with the UIPicker along with a UIToolBar with Done/Cancel buttons.
How can I make it so that just this half view slides up and the background view is still showing but dimmed or cant be played with.
I'm using this code so far:
- (void)showModalView
{
[self.popupView setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:self.popupView];
[UIView animateWithDuration:.2 animations:^{
[self.popupView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
}];
}
Here is a pic: http://www.box.net/shared/static/08ji4s0f6i1b8qubrtz6.png
#Jon:
METHOD-1:
Make your main view transperant by setting its alpha value to 0 and add a subview to the main view which is only half of the main screen and keep it opaque (alpha value as 1) as it would be by default.
Then simply present the view controller using present Modal View Controller.
Keep in mind that because of the transperancy you would be able to see half of the previous view, but wont be able to touch it as there is a transperant view.
METHOD-2:
Another work around is to animate a UIView which is of size half of the existing view.
Then you have to simply follow animation of the UIView.
Here as it is just a UIView that will be added as subview to existing view, you will be able to touch the rest of the screen.
So you can follow either of the methods as per your requirement.
Hope this helps you.
Here is what u need its an open source code on github TDSemiModalView having a half view date picker. Check the demo project inside the code. Here is the link.. Hope it solves your problem.
TDSemiModalClass

Cannot properly rotate a translated UIView on the iPad

I have an UIViewController that has two UIViews inside, whose layout (set in Interface Builder) is something like this (the magenta colored view is the UIViewController default view):
and I added the main view to a root view obtaining this effect (by not showing the darker view placing its frame at the bottom):
Now when the device rotates, what I obtain is this:
whereas I'd like to still hide the darker view.
This is the code I use to hide it when it appears (I use it in the viewDidLoad method):
- (void)hideAll:(float)time{
CGRect hiddenFrame = CGRectMake(0, 1024, self.view.frame.size.width, self.view.frame.size.height);
[self.view setFrame:hiddenFrame];
[self.view setNeedsDisplay];
}
and it appears to work, but when I call a variant of it when rotating (in willRotateToInterfaceOrientation:duration:), nothing happens:
CGRect hiddenFrame = CGRectMake(0, 748, self.view.frame.size.width, self.view.frame.size.height);
[self.view setFrame:hiddenFrame];
[self.view setNeedsDisplay];
What am I missing? have I to set some other view property in Interface Builder?
UPDATE
It seems to me that the coordinate system does not change after the device has been rotated (ie the origin set in the upper-left corner in portrait mode will become the upper-right after a clockwise rotation in landscape mode)
Check your struts and springs in IB. It maybe that when you autorotate, the strut fixing you to the top of the screen moves your frame back to the top.
Try adding your code to the didRotateToInterfaceOrientation method so it can run after rotation has occurred.
Why to you change the frame to hide it, and not just
[self.view setHidden:YES];
second thing is that you should try to set the "Autoresizing" panel to handle the orientation changes, and not by changing the frame of the view.
hope i understood you right.
shani
The problem I encountered can be faced in two ways (I hope this can save some time for someone in the future):
using an UIViewcontroller (loaded from xib) and only its view as the rotating view, that is my original attempt to solve it. In this case you have to programmatically set the frame for the view when you want to hide it, and by doing so you have to consider that the coordinate system for the controller remains untouched and does not rotate (ie. it is always originated from the same corner)
using a UIView (loaded from xib) inside an already existing UIViewcontroller, in this way the view will automatically rotate and resize and you will not have to take the proper coordinates value into account at each rotation (this is by far the simplest way)