Showing UIPickerView when cell is selected - ios

For my app I’m implementing in-app settings using tableView with Dynamic prototype cells. Inside cell I’m showing main title and sub title. What I would like to achieve is when user clicks on one of the cells (that represents specific settings) the pickerView will slide from the bottom of the screen showing the options that user can pick. I’ve seen few tutorials where this pickerView is presented inside a cell as it is e.g. in iOS calendar app but I don’t need that – all will be fine if it will slide from the bottom actually in a same way as it is when you are having pickerView as inputView for your text field (e.g. textField.inputView = pickerView) and click to the text field. I appreciate any help you can provide guys! Thanks in advance!

You can create a custom view xib in which you can have pickerView,when user click on cell just show the custom view with animation.
viewPicker = CGRectMake(0, 490, 320, 460);
For the animation from bottom to top add below:
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseIn
animations:^{
viewPicker.frame = CGRectMake(0, 0, 320, 460);
}
completion:^(BOOL finished){
}];
[self.view addSubview:viewPicker];
For removing the view
[UIView animateWithDuration:1.5
delay:0.5
options: UIViewAnimationCurveEaseIn
animations:^{
viewPicker.frame = CGRectMake(0, 490, 320, 460);
}
completion:^(BOOL finished){
if (finished)
[viewPicker removeFromSuperview];
}];

Related

Search As in IOS8 Calender app

I'm wondering how i can achieve the same search function as in the calender app. When u click the RightBarButton then a new navigationBar with the searchBar animate on top of the existing and hwn u click cancel it will animate away. I guess this is a UISearchDisplayController which appears on the top, but how can i do something like this?
Here u see an illustration so when u click searchButton searchBar appear from the top and when u press done it animates away again.
You should try to show the search bar by using:
At tap:
[UIView animateWithDuration:.5 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
_collectionView.center = CGPointMake(160, 700);
} completion:^(BOOL finished) {
[self presentViewController:clockTappedController animated:NO completion:nil];
}];
In viewWillAppear:
[UIView animateWithDuration:.5 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
_collectionView.center = CGPointMake(160, 528);
}
completion:^(BOOL finished) {
}];
I've used it for collection view, but i think that you can do the same using the searchbar.
Loading the searchbar off of the screen and then get it slide down at tap on the icon. When you tap on done you put again the searchbar off the screen.

Custom UIActivityViewController-like view that slides up and down

Is there a way to subclass or customize UIActivityViewController to create a sort of custom view? For example, see the image below from the app Overcast. I want to create a view similar to that, where if you tap a button, the view pops up and when you tap outside of the view, it slides back down.
Why not use an UIView ? Set it's initial frame's y value to -self.customView.frame.size.height and animate it's frame to the normal position using [UIView animateWithDuration]
-(void)showCustomView{
[self.customview setFrame:CGRectMake(0, -self.customView.frame.size.height, self.view.bounds.size.height+self.customView.frame.size.width, self.customView.frame.size.height)];
[UIView animateWithDuration:0.25 animations:^{
[self.customView setFrame:CGRectMake(0, -self.view.frame.size.height, self.view.bounds.size.height-self.customView.frame.size.width, self.customView.frame.size.height)];
}];
}
-(void)hideCustomView{
[UIView animateWithDuration:0.25 animations:^{
[self.customView setFrame:CGRectMake(0, -self.customView.frame.size.height, self.customView.bounds.size.height+self.customView.frame.size.width, self.customView.frame.size.height)];
}];
}
Add an UITapGestureRecognizer and call hideCustomView when tapped outside the customView

How to show the TableView (like dropdown) on Button Click in iPhone?

I have tried this code. http://www.mediafire.com/download/bvoqrkn82sd6az9/tablesample.zip ..Here, It will display the Table View. But I need to create a tableview whenever I click the button, it should display the list of Tableview like dropdown as it is in this screenshot. http://www.mediafire.com/download/7jiwb0e00916gh9/Table+View.PNG This is what I need to display. Your help is highly appreciated. Thanks in advance.
You can change height of tableView with animation. Set time according your suitability.
For Expansion:
[UIView animateWithDuration:1
delay:0.0
options: UIViewAnimationYourChoice
animations:^{
CGRect frame = self.tableView.frame;
frame.size.height = 300;
self.tableView.frame = frame;
}
completion:^(BOOL finished){
NSLog(#"Done!");
}];
For shrinking:
[UIView animateWithDuration:1
delay:0.0
options: UIViewAnimationYourChoice
animations:^{
CGRect frame = self.tableView.frame;
frame.size.height = 0;
self.tableView.frame = frame;
}
completion:^(BOOL finished){
NSLog(#"Done!");
}];
There is no option for dropdwon in IOS SDK. If you need this follow like this.
On the click of this button you'll have to load a UIView or UITableView which will come exactly down to your UIButton.
This custom UIView or UITableView will act as your drop down.
Once your use is complete you can either hide it or remove it.
I hope it will hepl you.. Instead of dropview you can use UIPopoverController to show the UITableView
I have implemented this , You can achieve this by adding the button on the first row of any section and load other rows by the click on the first row with UITableViewRowAnimationTop using beginUpdate.
So now every first row of the section with index==0 will be a dropdown button and other rows starting from index=1 will be your data rows representing the information.

Toggling UITableViewCell selectionStyle causes labels on cell to disappear

I have a custom subclass of UITableViewCell. On my storyboard, it basically has a containerView (UIView *), that has some labels on it, and a UISwitch. I add a gesture to slide my tableViewCell to the right to show some detail controls underneath the containerView, and then another gesture to slide the original view back. The animation code looks like this:
- (void)showCustomControls:(UISwipeGestureRecognizer *)gesture {
[UIView animateWithDuration:0.3 animations:^{
[self.containerView setFrame:CGRectMake(self.frame.size.width - kTableViewCellSwipedWidth, 0, self.frame.size.width - kTableViewCellSwipedWidth, kOverviewTableViewCellHeight)];
}completion:^(BOOL finished) {
self.isReveal = YES;
self.selectionStyle = UITableViewCellEditingStyleNone;
}];
}
- (void)hideCustomControls:(UISwipeGestureRecognizer *)gesture {
[UIView animateWithDuration:0.3 animations:^{
[self.containerView setFrame:CGRectMake(-kTableViewCellBounceWidth, 0, self.frame.size.width, kOverviewTableViewCellHeight)];
}completion:^(BOOL finished) {
[UIView animateWithDuration:0.1 animations:^{
[self.containerView setFrame:CGRectMake(-kTableViewCellBounceWidth / 2, 0, self.frame.size.width, kOverviewTableViewCellHeight)];
}completion:^(BOOL finished) {
[self.containerView setFrame:CGRectMake(0, 0, self.frame.size.width, kOverviewTableViewCellHeight)];
}];
self.isReveal = NO;
self.selectionStyle = UITableViewCellSelectionStyleBlue;
}];
}
I noticed if I left the selectionStyle on, with the row open, it looked kind of funny. So I wanted to turn the selectionstyle off. So the code in there is to turn on and off the selection style when the row is open or closed. It works, however the weird thing is, when hideCustomControls gets called, and my original row slides back into place, the labels on the container view all go away. I have a little edge of the original row that shows, and when that is showing, the labels are there. But the second that the row slides all the way in place, all the labels disappear. The UISwitch which is also on the containerView never has problems though. It is always present. Is there a reason why this may be happening? When I remove the selectionStyle code in both methods, this problem goes away. Thanks in advance.
Edit:
I put in the correct code to animate using NSLayoutConstraint. Now the problem is the UIView subclasses I have on the view underneath show through to the top view when my row slides back into place. Not sure why this happens...

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.

Resources