How to present datepicker only upon click of a button - ipad

I need to know if a date picker can be presented like an alert view upon the click of a button. So far, I have hidden the date picker in viewdidload method and set hidden=no in the method for the button.
I intend to store the date within Core Data.

Create the pickerView, place it outside of your view bounds, add it as a subview and use animation to slide it up. Something like the below should work...
CGRect frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 215);
UIPickerView *typePicker = [[UIPickerView alloc] initWithFrame:frame];
[self.view addSubview:typePicker];
[UIView beginAnimations:#"slideIn" context:nil];
[typePicker setCenter:CGPointMake(typePicker.center.x, self.view.frame.size.height - typePicker.frame.size.height/2)];
[UIView commitAnimations];

You put the date picker in a subview and then present the subview at the click of a button. You probably want the subview to slide in from the side or bottom.

Related

iOS - Insert subview between the background and toolbar of another view

Pardon my ugly illustration below:
I have a view controller A that has a toolbar T at the bottom; toolbar is part of controller A, created by choosing "Opaque Toolbar" as "Bottom Bar" in the Attributes Inspector of view controller A. I'd like a banner B to slide up from the top of toolbar T, stay there for 2 seconds then disappear. Banner B is not within the view hierarchy of controller A. The issue right now is that the banner covers the toolbar during the sliding up process; I'd like the notification banner to emerge from the top of the toolbar, initially completely covered by the toolbar, instead of covering the toolbar.
Changing the layer index of the banner doesn't work, because the banner is not within the layer system of the view below it.
Here's my code snippet that adds the banner and animates it:
[containerView addSubview:innerView];
// Animate In
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
[innerView setFrame:target];
} completion:^(BOOL finished) {
if (finished) {
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapped:)];
[innerView addGestureRecognizer:tapGestureRecognizer];
}
}];
Is there a way to insert the banner so that it appears above the background of controller A but below the toolbar of the controller?
Maybe you can try :
[self.view bringSubviewToFront : toolbarView]; //Top level
[self.view insertSubview:bannerView belowSubview: toolBarView]; //below your toolbar
I assume your containerView is the view of a UINavigationController, as you cannot add a toolbar in the attributes inspector for UIViewController. I would suggest you just add the banner to self.view
[self.view addSubview:innerView];
If you feel like this will not work. You should probably subclass UINavigationController and add the subview of it.
[self.view insertSubview:bannerView belowSubview: self.toolbar]; //toolbar is a property of UINavigationController
I suppose it's possible to say something like:
[self.navigationController.view insertSubview:bannerView belowSubview: self.navigationController.toolBarView];
Generally you want view controllers to manager their own view hierarchy. So it is better to avoid the third options.

iOS Keyboard Making View Disappear

I am having a bit of an issue here. I have my main view for my application, for different windows. I have put them off the view sight and they're animated to move into view when they are required, I have never had an issue with this before until I decided to create a text field. When I click the button to bring the view into show it appears, but when I click the text field to type and the keyboard loads the view disappears, but if I click the button to bring the view back the text field will be entered and ready to type. Anyone got any solutions? I am attaching the code below of the way the view is appearing.
Thanks,
CurtisB
- (IBAction)login:(id)sender {
sidebutton = #"0";
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.0];
[self.blackhide setFrame:CGRectMake(self.blackhide.frame.origin.x -750, self.blackhide.frame.origin.y, self.blackhide.frame.size.width, self.blackhide.frame.size.height)];
[UIView setAnimationDuration:0.5];
[self.button2 setFrame:CGRectMake(self.button2.frame.origin.x - 300, self.button2.frame.origin.y, self.button2.frame.size.width, self.button2.frame.size.height)];
[self.mainview setFrame:CGRectMake(self.mainview.frame.origin.x - 300, self.mainview.frame.origin.y, self.mainview.frame.size.width, self.mainview.frame.size.height)];
[self.sidebarview setFrame:CGRectMake(self.sidebarview.frame.origin.x - 376, self.sidebarview.frame.origin.y, self.sidebarview.frame.size.width, self.sidebarview.frame.size.height)];
[UIView setAnimationDuration:0.0];
[self.loginview setFrame:CGRectMake(self.loginview.frame.origin.x + 376, self.loginview.frame.origin.y, self.loginview.frame.size.width, self.loginview.frame.size.height)];
}
Try to bring the subview you want at the top to front by using following code:
[parentView bringSubviewToFront:childView];
For example, if you want to show VIEW_A, do that code whenever you are un-hiding that view. If still you get that issue, put that code when keyboard appears i.e. in UITextfield delegate method..
Add comment if you are still stuck..

Mapkit custom callout slide view from bottom

I have a map which has multiple Annotations on it. When I click one I want to slide a small UIView from the bottom with some information about this pin. If I click on a button called more I want the view to expand upwards with more information in it.
I'm not sure how to do this the right way. My idea is to define a new xib and view controller for the custom callout. But I only want to display a small portion of that view so should I set its frame from the beginning to a fixed small value or rather use autolayout to shrink it to its content? And how can I slide it up from the bottom? I think I need to show it either modally or as a childviewcontroller and use some animation.
When the user clicks on more I would use another DetailViewController with a xib file which either would be shown also modally or also as a childviewcontroller. Is there any example how to achieve something like this? Or are there any better ways to do this?
For now the custom callout view would be the same for each Annotation. But I would have three different DetailViewControllers depending on which Annotation was clicked.
My basic idea is to separate these things so my MapViewController won't get too big.
I wouldn't use a view controller for the slide-in view. Just create a UIView with a frame that's just outside of your main view frame, and make it a subview. Like this:
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 200)];
[self.view addSubview:v];
self.infoView = v;
You can do that in viewDidLoad, or wherever you want in the initial setup of your view. It won't be visible because it's just off the bottom of the screen. Then when the user taps the callout button, animate your infoView into position like this:
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
// Populate infoView with whatever info you want to show about the annotation
//
// ...
//
// Then animate the view into position
[UIView beginAnimations:#"infoView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
self.infoView.center = CGPointMake(0, self.view.frame.size.height - 200);
[UIView commitAnimations];
}

Animating two UIView subviews at the same time does not work

For some reason i am not able two animate two subviews postion. I have wrote the following
[self addChildViewController:self.photosViewController];
[self.photosViewController.view setFrame:CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:self.photosViewController.view];
[UIView animateWithDuration:1 delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
[self.stepsView setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[self.photosViewController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
}
completion:^(BOOL finished) {
if (finished) {
button.tag = 0;
}
}];
self.stepsView is an IBOutlet UIView and self.photosViewController.view is an child view controllers view that has been added to the view.
With the current code only the self.PhotosViewController.view animates. However if i comment out the line where i add the child view controllers view as a subview then the self.stepsView animates correctly.
Even if i add the child view controller and its view before this method is called the same error happens.
Need help as i ran in to this a couple of months back with another app and had to do a dirty hack to get around it and now want to solve this.
Thanks
In the section on view animation in the View Programming Guide there is a specific mention of how to animate subviews.
Basically, you should use transitionWithView:duration:options:animations:completion: rather than animateWithDuration:delay:options:animations:completion:.
The first view will not be visible, because its origin.y is beyond the height of the visible view. If it was not visible when the animation starts, you will of course see nothing.
The second view is changed to fill the screen. Again, what you see depends on its initial position.

Animated Subviews

I have a split view controller in my Ipad app, in which the detail view has subviews which are UITableView's.
The functionality I am trying to implement is to get an info view at the same position of a subview when a button(info button) on the subview is pressed. I need to get this info view by animation and that animation is that when the info button is pressed, that subview alone would flip (UIAnimationOptionFlipFromRight) and the info view would show...
This is how try to implement it -
-(void) showInfoView: (id)sender
{
infoView = [[InfoViewController alloc] initWithNibName:#"ViewViewController" bundle:nil];
infoView.view.frame = CGRectMake(250, 300, 200, 200);
[UIView transitionWithView:self.view duration:1
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[self.view addSubview:infoView.view];
}
completion:nil];
}
When I run the simulator and press the info button on any subview, what happens is that the animation happens perfectly, i.e. the subview flips from the right but the infoView is not getting displayed.
It would be great if someone could tell me where I am going wrong here.
The basic steps of performing an animation to onscreen is as follows:
Create the view.
Move it to the initial (offscreen) position
Add to the view hierarchy
Perform the animation.
It seems like you're skipping step 3 and possibly step 2.
Did you try setting the subview frame to the frame of your superview, i.e
info.View.frame = self.view.frame;

Resources