PDA

View Full Version : PickerView in miss location after rotated




mikezang
Oct 16, 2010, 06:07 AM
I use code as below to show a PickerView, but is not located at middle of center, then if I rotated, the PickerView is not to rotated, what should I have to implement for tight showing?

- (void)showPickerView {
if (pickerView == nil) {
pickerView = [[UIDatePicker alloc] initWithFrame: CGRectMake(0.0, 0.0, 0.0, 0.0)];
}

if (self.pickerView.superview == nil) {
[self.view.window addSubview: self.pickerView];

// size up the picker view to our screen and compute the start/end frame origin
// for our slide up animation compute the start frame
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
CGSize pickerSize = [self.pickerView sizeThatFits:CGSizeZero];
CGRect startRect = CGRectMake(0.0, screenRect.origin.y + screenRect.size.height, pickerSize.width, pickerSize.height);
self.pickerView.frame = startRect;

// compute the end frame
CGRect pickerRect = CGRectMake(0.0, screenRect.origin.y + screenRect.size.height - pickerSize.height, pickerSize.width, pickerSize.height);

// start the slide up animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];

// we need to perform some post operations after the animation is complete
[UIView setAnimationDelegate:self];

self.pickerView.frame = pickerRect;

// shrink the table vertical size to make room for the date picker
CGRect newFrame = detail.frame;
newFrame.size.height -= self.pickerView.frame.size.height;
self.detail.frame = newFrame;
[UIView commitAnimations];
}
}



mikezang
Oct 16, 2010, 10:55 AM
I knew why PickerView is not at the center of screen, because code as below return a mistake size. I run in Portrait mode, but system gives me a Landscape width. Is this a bug in SDK?
CGSize pickerSize = [pickerView sizeThatFits:CGSizeZero];

ianray
Oct 16, 2010, 12:32 PM
I run in Portrait mode, but system gives me a Landscape width. Is this a bug in SDK?

Might be. How does the code behave on the hardware? Have you tried the iOS 4.2 beta?

Regarding centre positioning, set screenRect.size.width as the width in the startRect and pickerRect. (UIDatePicker centres itself within the given rectangle.)

mikezang
Oct 16, 2010, 12:44 PM
Might be. How does the code behave on the hardware? Have you tried the iOS 4.2 beta?

Regarding centre positioning, set screenRect.size.width as the width in the startRect and pickerRect. (UIDatePicker centres itself within the given rectangle.)
I used code as below to correct miss width. Only in 4.1.

CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
CGSize pickerSize = [pickerView sizeThatFits:CGSizeZero];
pickerSize.width = screenRect.size.width;


By the way, do you have any idea for rotation problem?

ianray
Oct 16, 2010, 05:03 PM
By the way, do you have any idea for rotation problem?

Have you tried to use a popover? I think that is the natural human-interaction paradigm with the iPad. (I don't have an iPad.)

Matthew Yohe
Oct 16, 2010, 05:13 PM
Which version of the SDK is this? ie. Why is there a window around the simulator?

mikezang
Oct 16, 2010, 09:51 PM
Which version of the SDK is this? ie. Why is there a window around the simulator?
You have special eyes.

I am using iOS SDK 4.1 and do my job by VNC from a ThinkPad to Mac mini.

Have you tried to use a popover? I think that is the natural human-interaction paradigm with the iPad. (I don't have an iPad.)
Can you tell me where I can find a sample for PickerView in Popover?

dejo
Oct 16, 2010, 10:04 PM
Can you tell me where I can find a sample for PickerView in Popover?
By this point I would hope you would be able to code your own sample for such a fairly trivial need.

mikezang
Oct 17, 2010, 12:36 AM
By this point I would hope you would be able to code your own sample for such a fairly trivial need.
Really?

robbieduncan
Oct 17, 2010, 03:14 AM
Really?

Absolutely. The fact you even question this shows that copying "sample code" and saying to yourself "I understand that" has taught you somewhere between absolutely nothing and very little. Perhaps you should accept that this approach is not working and actually sit down with a book and learn.

mikezang
Oct 17, 2010, 03:59 AM
Absolutely. The fact you even question this shows that copying "sample code" and saying to yourself "I understand that" has taught you somewhere between absolutely nothing and very little. Perhaps you should accept that this approach is not working and actually sit down with a book and learn.
Your suggestion is no any suggestible all time!

You are not the Demi-God, but the God!

If anyone can do programming just read book, who needs this forum?

ianray
Oct 17, 2010, 07:46 AM
Can you tell me where I can find a sample for PickerView in Popover?

You have probably seen in the documentation that UIPopoverController is initialized with a view controller whose job is to provide the content.

Are you familiar with views and view-controllers?

mikezang
Oct 17, 2010, 07:51 AM
You have probably seen in the documentation that UIPopoverController is initialized with a view controller whose job is to provide the content.

Are you familiar with views and view-controllers?
A little, though not enough. Here is found by me at first... (http://forums.macrumors.com/showthread.php?t=1032140)

But I want to use a DatePicker in popover and in programming, it is not a controller so that a UIViewController might be neede.

I want to know if there is simpler way to use a DatePicker in popover, it seems like there is no such story on Internet...

ianray
Oct 17, 2010, 11:21 AM
A little, though not enough. Here is found by me at first... (http://forums.macrumors.com/showthread.php?t=1032140)

But I want to use a DatePicker in popover and in programming, it is not a controller so that a UIViewController might be neede.

I want to know if there is simpler way to use a DatePicker in popover, it seems like there is no such story on Internet...

The documentation clearly states that: UIPopoverController is initialized with a view controller whose job is to provide the content.

There is no simpler way: you must create a hierarchy where there is a UIViewController which owns the UIDatePicker.

dejo
Oct 18, 2010, 10:25 AM
Really?
I thought really. I guess I was wrong.

If anyone can do programming just read book, who needs this forum?
Most of the books we talk about around here are meant to teach you the fundamentals (and not always all of them). It is then up to you, the programmer, to use your creativity and ingenuity to solve your own problems based on your knowledge of that foundation. That, to me, is where the forum comes in: when you need help for something that's beyond the basics or when writing code that applies the fundamentals but in a way unique to your specific application. Or occasionally when a fundamental confuses you and would like it explained in a different manner.

A little, though not enough.
I would take this as your cue then to go learn enough about how views and viewcontrollers work.

Also, remember that an important skill (probably the most important) of programming is being able to take a larger problem and divide it into smaller problems, sometimes called "divide-and-conquer", which you solve individually and then piece together.

So, for example, for your recent problem, I would break it down into:
1) how do I add a date picker to a view that has a viewcontroller
2) how do I take a view, any view, that has a viewcontroller and present it from within a popover controller

Then, it's just a matter of combining 1) and 2). Not always is this an easy thing but in this case, I think it's fairly trivial.

Hope that helps.

mikezang
Oct 18, 2010, 07:24 PM
I thought really. I guess I was wrong.


Most of the books we talk about around here are meant to teach you the fundamentals (and not always all of them). It is then up to you, the programmer, to use your creativity and ingenuity to solve your own problems based on your knowledge of that foundation. That, to me, is where the forum comes in: when you need help for something that's beyond the basics or when writing code that applies the fundamentals but in a way unique to your specific application. Or occasionally when a fundamental confuses you and would like it explained in a different manner.


I would take this as your cue then to go learn enough about how views and viewcontrollers work.

Also, remember that an important skill (probably the most important) of programming is being able to take a larger problem and divide it into smaller problems, sometimes called "divide-and-conquer", which you solve individually and then piece together.

So, for example, for your recent problem, I would break it down into:
1) how do I add a date picker to a view that has a viewcontroller
2) how do I take a view, any view, that has a viewcontroller and present it from within a popover controller

Then, it's just a matter of combining 1) and 2). Not always is this an easy thing but in this case, I think it's fairly trivial.

Hope that helps.
Thanks for your suggestion.