Weird sizing issue with UIPickerView - iphone

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?

Related

Change view alternative

I have an window based app with some ViewController.
I switch from one view to another using :
[self.view addSubview:newViewController.view];
Everything works fine but I have a problem:
When I change the view to a scrollView which has frames more than 320x480 I can not return to previous frames.I mean I change the the views further normally but I have a bigger frame and I see the rest of the content from the scrollView which is not covered by the current view.
Is there any method to set the superview size back to 320x480?
Thanks
You can set the frame of a view back to 320X480 manually by doing something like:
yourView.frame = CGRectMake(0,0,320,480);
When you switch back are you removing the scrollview from the superview as well? [scrollview removeFromSuperView]; ?

A toolbar is not where it should be

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.

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)

UIView loses background when animated up

I am working on an iOS app and am having trouble with a really tall UIView (2400px tall). The UIView contains a really long form that's been broken down into 5 parts. As the user completes one part of the form, I would like to slide the UIView up to reveal the next part. I present the UIView modally.
The problem that I am having is that when I slide up the UIView, the background slides up along with the objects in the first section and the next section is left with a clear background. The code I use to slide the UIView is:
- (IBAction)slideUp {
// Slide the view up the screen to reveal the next section
CGRect frame = self.view.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.75];
frame.origin.y = -480;
self.view.frame = frame;
[UIView commitAnimations];
}
All of the objects in the really tall UIView slide up fine, I'm just losing my background color. Any idea why?
Thanks!
Is your background being rendered by some sort of "background view" that's sized to fit the screen?
In any case, you should probably use a UIScrollView with scrolling disabled instead of a really long UIView. You can then simply animate the contentOffset property to scroll the controls up, but the scrollview itself can simply be screen-sized.
Instead of using self.view.frame, i would highly recommend you create an IBOutlet for the really long view so that the code looks like self.longView.frame.
This will help making it clear which views you are working with.
Right now i am betting that you are animating the wrong view.