iPad UIPickerView causing problems - iphone

Can someone show me how I can get a UIPickerView working on the iPad? I'm trying to have a UIPickerView in the middle of the screen. Here is the current code I have:
if(IDIOM == IPAD)
namePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(200, 345, 400, 216)];
else
namePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 245, 0, 0)];
namePickerView.delegate = self;
namePickerView.showsSelectionIndicator = YES;
So this just puts the picker view on the far left. On the iPhone, everything is perfect. But on the iPad, this doesn't work. As soon as I try to scroll through the values, nothing movies. The UIPickerView does not respond to any touches. What is the issue here? I just want to put a UIPickerView of default size in the middle of my iPad screen, 345 pixels down.

UIPickerViews on the ipad don't have a default size (ie width).
change
namePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 345, 0, 0)];
to
namePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 345, 400, 216)];

Related

Two picker views in the same UIViewController

I have a UIViewController that contains two picker views. For some reason when I run the project one picker view is overshadowing the other. How can I set the positions, height and other parameters in code?
Why are you using two picker view ? You can change the content of the pickerview when needed.
Even if u want to use two of them, the picker would be at the bottom anyways. Use show and hide property of the pickerview to handle your required task
You have to implement -initWithFrame: method (assuming that you're instantiating the view in code). Here's an example showing to picker views -
UIPickerView *myPickerView1 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
[self.view addSubview:myPickerView1];
UIPickerView *myPickerView2 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 320)];
[self.view addSubview:myPickerView2];
If you see this image below, they are not overshadowing one another. I hope this easy explanation helps. Welcome to iOS Development!
you can do this way
//first picker
optionPicker1 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 200)];
[self.view addSubview:optionPicker1];
//second picker
optionPicker2 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 200)];
[self.view addSubview:optionPicker2];

Side sliding tabs in iPhone/iPad application

Is it possible to create a side sliding tabs (like the menu in WP7; I'm not sure what the correct term is) for iPhone/iPad applications? I haven't implemented any code yet, right now I'm assuming that it could probably be done with multiple vertical UIScrollViews within a horizontal UIScrollView.
I've seen this kind of menu in iPad applications (Discovr Music/Movies), and would like to implement it in iPhone if it is possible. Also, is this kind of menu against any of Apple's UX policies?
Thanks!
This is possible and you can do it.
For example:
UIView *wrapper = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 460)];
UIView *subView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[wrapper addSubview:subView1];
UIView *subView2 = [[UIView alloc] initWithFrame:CGRectMake(320, 0, 320, 460)];
[wrapper addSubview:subView2];
[scrollView setContentSize:wrapper.frame.size];
[scrollView setPagingEnabled:YES]; //Here's what you want to do!
[scrollView addSubview:wrapper];
Didn't test the code, but it should work.
Important is to add Subview to the ScrollView. (It would also work if you don't use a wrapper, but I often use it, because of the size.)

UIPIckerView in UIPopoverController

I'm not trying to resize the PickerView's height. I'm fine with having the default size, which I believe is 320 x 216. I created this code to present a pickerView in my popovercontroller, however, I get these messages on the console:
2
011-06-30 13:18:28.125 MiGenome[64357:207] -[UIPickerView setFrame:]: invalid height value 1024.0 pinned to 216.0
2011-06-30 13:18:28.126 MiGenome[64357:207] -[UIPickerView setFrame:]: invalid height value 448.0 pinned to 216.0
2011-06-30 13:18:28.127 MiGenome[64357:207] -[UIPickerView setFrame:]: invalid height value -16.0 pinned to 162.0
I don't know why I get this since I'm trying to use the picker default size in the popover. Here's my code. Thanks.
- (IBAction)presentSortPopover {
UIViewController *sortViewController = [[UIViewController alloc] init];
UIPickerView *sortPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, sortViewController.view.bounds.size.width, sortViewController.view.bounds.size.height)];
sortViewController.view = sortPickerView;
sortViewController.contentSizeForViewInPopover = CGSizeMake(320, 216);
sortPickerView.delegate = self;
sortPickerView.dataSource = self;
sortPickerView.showsSelectionIndicator = YES;
self.SortPopover = [[UIPopoverController alloc] initWithContentViewController:sortViewController];
[self.SortPopover presentPopoverFromRect:_sortButtonPop.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[sortPickerView release];
[sortViewController release];
}
I had the same problem until I embedded the UIPickerView in a generic UIView with the same dimensions (0, 0, 320, 216), and set the view controller's view property to the UIView.
Also, I used the setPopoverContentSize:animated: method on the UIPopoverViewController to set the popover dimensions, rather than setting it on the UIViewController.
Hope that helps.
I think this line is the culprit.
UIPickerView *sortPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, sortViewController.view.bounds.size.width, sortViewController.view.bounds.size.height)];
try
UIPickerView *sortPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
UIViewController has a method called contentSizeForViewInPopover.
If you set the expected size for your view controller using it (using a CGSize) you will be able to prevent the UIPopoverController from resizing itself wrong.

iOS 4.3 changed transformation on UIImagePickerController's camera overlay view

After testing my App on iOS 4.3 I noticed that the camera overlay of my UIImagePickerController has an added transformation that stretched the content extremely. Pre iOS 4.3 everything shows up correctly.
Here is what I do
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraOverlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
cameraOverlay.backgroundColor = [UIColor clearColor];
cameraOverlay.userInteractionEnabled = NO;
//add subviews to camera Overlay
imagePicker.cameraOverlayView = pauseButton;
Any ideas what I have to do to get rid of the added transformation?
OK found the answer. ios 4.3 requires to have the camerOverlay as big as the screen is. So my 200x200 camera overlay was enlarged.
If I change the line:
cameraOverlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
to
cameraOverlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
it works :).

iPad - How to move Mulitple UIViews side-by-side

How to move multiple UIViews Side-by-Side just like an twitter application working in iPad. With full of effects animation and rotations.
You should take a look at the UIScrollView with paging enabled.
Make all your views and put them next to one another inside a UIScrollView. i.e.
// Get your views
MyView *v1 = [[[MyView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
MyView *v2 = [[[MyView alloc] initWithFrame:CGRectMake(320, 0, 320, 480)] autorelease];
MyView *v3 = [[[MyView alloc] initWithFrame:CGRectMake(640, 0, 320, 480)] autorelease];
// Make the UIScrollView
UIScrollView *scroll = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
[scroll setPagingEnabled:YES];
[[scroll addSubview:v1];
[[scroll addSubview:v2];
[[scroll addSubview:v3];
[scroll setContentSize:CGSizeMake(960, 480)];
// add the scroll view to your view
[[self view] addSubview:scroll];
Now, the three views (v1, v2 and v3) are next to each other in a scroll view whose content is much wider the view. With paging enabled, they will scroll left and right but won't stop halfway through a view.
Take a look at view animations:
http://www.switchonthecode.com/tutorials/creating-basic-animations-on-iphone