Toggle Searchbar View using UIScrollView - uitableview

I have a search bar embedded above a tableview which is visible as soon as the view is opened i want it to be hidden when the page loads and on click of the search button (Bottom left corner) i want the searchbar to get animated from top. I have read that this can be done using UIScrollview, but none of the tutorials have been able to help me.

For
1)I want it to be hidden when the page loads and on click of the search button
In your search button clicked...
if(self.searchBar.isHidden)
{
[sender setSelected:YES];
self.searchBar.hidden=NO;
[self resetFrame:tableView toFrame:CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y+44, tableView.frame.size.width, tableView.frame.size.height) withDelay:0.5];
}
else if(!self.searchBar.isHidden)
{
[sender setSelected:NO];
self.searchBar.hidden=YES;
[self resetFrame:tableView toFrame:CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y-44, tableView.frame.size.width, tableView.frame.size.height) withDelay:0.5];
[self.searchBar resignFirstResponder];
}
-(void)resetFrame:(UIView *)view toFrame:(CGRect )frame withDelay:(float)delay
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:delay];
[view setFrame:frame];
[UIView commitAnimations];
}
}
Just add the above when you click search button or if want it to be hidden when page shows add it in the viewWillAppear method
2)i want the searchbar to get animated from top.
Add the searchbar to the view by making its y axis below 0 example -100 and once page loads set its actual frame use resetFrame method to bring your search bar from top

Related

Putting UISearchBar in a custom UITableview causing weird animation

Basically, I am including two buttons located below the navigation bar. And below these two buttons, there is a UITableView, with the UISearchBar as its header view. However, when I click the search bar, the animation moves very strange.
Then I try to use animation to move the UITableView together with the search bar to the top,
the animation goes like this
The code added to the table view is like this:
- (BOOL) searchBarShouldBeginEditing:(UISearchBar *)searchBar {
CGRect tableViewFrame = self.myTableView.frame;
tableViewFrame.origin.y = 0;
[UIView animateWithDuration:0.1
animations:^{
self.myTableView.frame = tableViewFrame;
}
completion:nil];
return YES;
}
I am wondering how to move the UISearchBar to the top of the screen, together with the whole table view with smooth animations.
- (BOOL) searchBarShouldBeginEditing:(UISearchBar *)searchBar {
[UIView animateWithDuration:0.1
animations:^{
[ searchBar setFrame:CGRectMake(searchBar.frame.origin.x, 0, searchBar.frame.size.width, searchBar.frame.size.height)];
[self.myTableView setFrame:CGRectMake(myTableView.frame.origin.x, searchBar.frame.size.height, self.myTableView.frame.size.width, myTableView.frame.size.height)];
}
completion:nil];
return YES;
}
try this code

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..

Hidding view with table scroll

I'm searching for idea how to implement a table view with moving view on top of it.
So the idea is something similar to navBar in facebook app. When you scroll up this (red) view is moving up and hiding, when you scroll up its going up and when you scroll down its revealed. This is not nav bar so most of the pods I've found are not working in this situation. This cannot be tableView header or section header as well.
You need added this view above table:
[self.tableView.superview insertSubview:view aboveSubview:self.tableView]
Or you can do it in storyboard.
When you table scroll down hide view, when up show.
[view setHidden:YES];
Also u could change table inset to the top of the superview.
self.tableView.contentInset = self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(self.tableView.contentInset.top -, self.tableView.contentInset.left, self.tableView.contentInset.bottom, self.tableView.contentInset.right);
I think fast way to do it use gesture recognizers to recognize reveal and hide actions and than you can use methods like below,
[UIView animateWithDuration:0.5 animations:^{
[attachedView setAlpha:0.0f];
} completion:^(BOOL finished) {
[attachedView setHidden:YES];
}];
and for reveal attached view
[UIView animateWithDuration:0.5 animations:^{
[attachedView setAlpha:1.0f];
} completion:^(BOOL finished) {
[attachedView setHidden:YES];
}];
methods will help you to hide and reveal views gently.
Take a look at this library, it does exactly what you want to do
https://github.com/telly/TLYShyNavBar

UIKeyboard Disabling Touch Events

When the keyboard is displayed in my app, no touches will work in my view. I will tap a UITextField and the keyboard will be presented. Now that it is displayed, I cannot tap on other textfields,buttons or select text even in the active textfield.
Any ideas what may cause this
Thanks.
UPDATE 1:
I have found that because I animate the view upwards a little when the keyboard is displayed this is causing a problem. I have the master, view controller view. Inside this is formContainerView which contains my two UITextFields and UIButton.
I animate formContainerView up so that my fields aren't hidden behind the keyboard. I run the following code to do this:
[UIView animateWithDuration:duration delay:0 options:animationOptionsWithCurve(curve) animations:^{
[self.formContainerView setFrame:CGRectOffset(self.formContainerView.frame, 0, -220.0f)];
}
completion:^(BOOL finished) { }];
So I just offset the view by 220 pixels. If I set this to 0, i.e. don't animate the position, all touches work. But by moving the view up, all touches fail to work.
Why?
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
if ([txtfld_firstname isFirstResponder])
{
[txtfld_firstname resignFirstResponder];
[txtfld_secondname becomeFirstResponder];
}
return YES;
}
first set to the delegate for the textfield.
and after that write the above method when you click on the first textfield and after that press return button on the keyboard this (textfield delegate)method call and your keyboard disable.

Making image view disapear and re appear over the view controller

Hello Im having trouble with my image view. i have a login view controller and i have a UIButton when clicked an image view animates across the view controller which is this:
- (IBAction)alreadyUser:(id)sender {
[_usnernameField resignFirstResponder];
[_passwordField resignFirstResponder];
[UIView animateWithDuration:0.3 animations:^{_loginOverlayView.frame = self.view.frame;
}];
}
but i can’t figure out how to undo this action i tried [_loginOverlayView setHidden:YES];
but then it states hidden when i try to come back to it
Appear:
[_loginOverlayView setHidden:NO];
Disappear:
[_loginOverlayView setHidden:YES];
you can put before or after the animation to hide or show the loginOverlayView.

Resources