Quote:
Originally Posted by eddyxd
-- here is what i want to do --
I have view1(with some user info) and view2(with some UIDatePicker or other UI)
And after user touch the button "change" in view1 , the app will pop up view2(with down up animation) and the background of view2 is translucent, so we still can see part of view1 behind of view2.
After user finish changing in view2 and push "ok" button , view2 would pop out with up down animation back to view1.
-- here is what i have tried --
1. using addSubView and removeFromSuperView with customized animation.
It works perfectly when changing to view2, but it does't work when I pop back to view1(there is no animation...)
2. using presentModalViewController (I think it would be a better and smarter way!)
But everytime after view 2 sliding up to it's position , the view1 just disapper@@!! (view1 would perform perfectly as i want during view2 is sliding that is we still can see view1 behind part of view2@@)
So how could I figure out this problem??
ps: I tried to cancel the check-box:"Opaque"and "clear context before drawing" of view2 in IB, but still have not any effect in thisQQ.
Does anyone has any idea? or could you give some advice to implement this function what i want in more easier way.
Thanks.~ 
|
Pushing a modal view controller won't work because the system will take away the underlying view once the modal view controller is animated into place.
Here's what you need to do:
In the nib file for the view controller where you want present the date picker dialog, add a new view, just inside the view controller's main view. Make your new view the same size as it's parent view (full screen size). In IB, set the background color of your view to black (or white, depending on the look you want) with an opacity of .3 to .5. This will cause the view to partly obscure the view below, but allow it to show through slightly. Play with the opacity value to get the effect you want.
Add subviews centered inside that the "date picker view" that contain the UI elements you need, including a date picker, buttons, etc.
After you have the contents the way you want them, click the "hidden" checkbox on the outermost "date picker view". This will cause that view to not be drawn.
Create outlets and actions in your view controller to manage this new "date picker view". I suggest you group all the outlets, instance variables and methods in your code, and mark them with clear header/footer comments so you can remember what components go with your new view.
Add an IBAction method "showDatePickerView:". This method will be responsible for animating in your date picker view. Also create another method, "hideDatePickerView:" that will be responsible for reversing the process.
in showDatePickerView, do the following:
Code:
- (IBAction) showDatePickerView: (id) sender;
{
CGPoint viewCenter;
viewCenter = datePickerView.center;
//The following lines move the view off-screen to the top
//(while it's still hidden
viewCenter.y += datePickerView.superview.frame.size.height;
datePickerView.center = viewCenter;
//Now that the view is off-screen, make it visible
datePickerView.hidden = FALSE;
[UIView beginAnimations: @"slide_down" context: nil];
{
viewCenter = datePickerView.center;
//The following lines move the view on-screen from the top.
viewCenter.y -= datePickerView.superview.frame.size.height;
datePickerView.center = viewCenter;
}
[UIView commitAnimations];
}
Then, in your hideDatePickerView method, do this:
Code:
- (IBAction) hideDatePickerView: (id) sender;
{
CGPoint viewCenter;
[UIView beginAnimations: @"slide_up" context: nil];
{
viewCenter = datePickerView.center;
//The following lines move the view on-screen from the top.
viewCenter.y += datePickerView.superview.frame.size.height;
datePickerView.center = viewCenter;
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector: @selector(setPickerViewHidden)];
}
[UIView commitAnimations];
}
//This method gets called once the hide picker view animation is complete.
//It marks it as hidden again and resets the view back to it's original position.
- (void) setPickerViewHidden;
{
datePickerView.hidden = TRUE; //Mark the view as hidden again for next time.
CGPoint viewCenter;
viewCenter = datePickerView.center;
viewCenter.y -= datePickerView.superview.frame.size.height;
//Move the picker view back on-screen for next time.
datePickerView.center = viewCenter;
}