I'm trying to hide the search bar until the user scrolls up. It works but, when the user scrolls, the search bar appears white. I'm using this code to hide it :
self.tableView.contentOffset = CGPointMake(0.0, 44.0);
I also tried using :
CGRect newBounds = self.tableView.bounds;
newBounds.origin.y = newBounds.origin.y + self.SearchBar.bounds.size.height;
self.tableView.bounds = newBounds;
This is what happens :
This is how it should look like after scrolling:
Try replacing the TableView + Search Bar with a Search Display Controller and then place your code in the viewWillAppear.
self.tableView.contentOffset = CGPointMake(0.0, 44.0);
Ok so, thanks to Pyraego.com, I was able to solve my problem. First, I removed the search bar and I replaced it with a search display controller. Then, I used the method self.tableView.contentOffset = CGPointMake(0.0, 44.0); which worked perfectly (I added it in "viewWillAppear).
All the credit goes to Pyraego.com, I'm just posting this in case someone else has the same problem.
Related
This seems like it should be pretty straight forward but im really stuck. I basically want to start the app and it goes to the center view, where the user can swipe up down left or right to access four different views. the picture pretty much sums it up. I will make the text in the picture "swipe up for view 1" "swipe down for ....." buttons also that achieve the same thing as the swiping but I dont want to ask for too much so if anyone can help me out and show me how to program what Im looking for I would much appreciate it.
I was able to get it to be just one massive view but I realized that I want it to jump to every different view, not scroll and be half way there. and when I tried to make cgrect frames it was very confusing to keep it all in order.
Here,I am Providing you sample code.I just write code for two views.You just need to determine the views position according to scroll.
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if(scroll.contentOffset.y> 480 && scroll.contentOffset.x<320)
{
//where next view is you view which you need to display according your requirements.
next *pushnext = [[next alloc]initWithNibName:#"next" bundle:nil];
[self.view addSubview:pushnext.view];
CGRect frame = pushnext.view.frame;
frame.origin.x = 10;
pushnext.view.frame = frame;
[pushnext release];
}
else if(scroll.contentOffset.y<480 && scroll.contentOffset.x>320)
{
//where next view is you view which you need to display according your requirements.
next *pushnext = [[next alloc]initWithNibName:#"next" bundle:nil];
[self.view addSubview:pushnext.view];
CGRect frame = pushnext.view.frame;
frame.origin.x = 10;
pushnext.view.frame = frame;
[pushnext release];
}
}
I hope this will help you.
I have a tabbarview application that has a button in one of the tabs. When Pressing that button, something will happen, and the user will be switched to another tab.
I made an animation in that button:
UIView * fromView = self.tabBarController.selectedViewController.view;
UIView * toView = [[self.tabBarController.viewControllers objectAtIndex:0] view];
[UIView transitionFromView:fromView
toView:toView
duration:0.6
options:(UIViewAnimationOptionTransitionCurlDown)
completion:^(BOOL finished) {
if (finished) {
self.tabBarController.selectedIndex = 0;
}
}];
Which I got from here. However the problem is that after animating, I seem to have a gap on the top of the screen that is about as high as the status bar. Does anyone know what's causing this? This gap quickly closes when the animation finishes (which is when we do self.tabBarController.selectedIndex = 0
By the way, the problem still persist if I swap the animation to something else or even without animation.
Additional info, here's the frame details:
from frame: x:0.000000, y:0.000000, w:320.000000, h:411.000000
to frame: x:0.000000, y:0.000000, w:320.000000, h:431.000000
The tab bar controller's area also covers the area underneath the status bar. So it's own client view has origin.y of 20.
Thus you need to set the incoming view frame correctly before invoking the transition.
I've found a very hacky way to do it:
CGRect to = fromView.superview.frame;
to.origin.y -= 20;
fromView.superview.frame = to;
Anyone that can explain to me why I had to do this and a more elegant way to do this will get the answer accepted.
I am trying to add a UIActivityIndicator to my custom view (programmatically). I am using the following code. But I dont see anything on the screen. Any idea why ?
Thanks.
UIActivityIndicatorView *activityIndicator=[[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(75, 395, 200, 200)] autorelease];
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicator.center=self.view.center;
[self.view addSubview:activityIndicator];
UIActivityIndicator has its hidesWhenStopped property equal to YES by default - that is it is hidden if you do not start animating it. So to make it appear on the screen try one of the following (whichever is more suitable for you):
set hidesWhenStopped property to NO
start animating it (using -startAnimating method)
comment "activityIndicator.center=self.view.center;"
Another reason is maybe because you're not set the activity indicator position correctly. From what I see, you want to place the activity indicator to the center of it's parent view. But to do that, you must do something like activityIndicator.center = CGPointMake(self.view.frame.origin.x + self.view.bounds.size.width / 2.0, self.view.frame.origin.y + self.view.bounds.size.height / 2.0);
I've read multiple posts on this but it's not working properly for me. I'm using the latest 4.2 SDK.
The code I have is
self.tableView.contentOffset = CGPointMake(0.0, 44.0);
This partially works, it moves the search bar up a little bit, but it does not get hidden completely. I've tried increasing the value 44 to something greater and this had no affect what so ever! I'm calling this code in the viewDidLoad method of the table's view controller. Does anyone have any ideas?
Another approach should be...in viewDidLoad call:
self.tableView.contentInset = UIEdgeInsetsMake(-self.searchDisplayController.searchBar.frame.size.height, 0, 0, 0);
and implementing endDragging delegate method:
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
CGPoint offset = self.tableView.contentOffset;
CGFloat barHeight = self.searchDisplayController.searchBar.frame.size.height;
if (offset.y <= barHeight/2.0f) {
self.tableView.contentInset = UIEdgeInsetsZero;
} else {
self.tableView.contentInset = UIEdgeInsetsMake(-barHeight, 0, 0, 0);
}
self.tableView.contentOffset = offset;
}
setting content is to remove some "flickering"
also if You want searchbar to stick at the top, implement didScroll this way:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGRect sbFrame = self.searchDisplayController.searchBar.frame;
sbFrame.origin.y = self.tableView.contentOffset.y;
if (sbFrame.origin.y > 0) {
sbFrame.origin.y = 0;
}
self.searchDisplayController.searchBar.frame = sbFrame;
}
I hope this will help (took me few days to figure out:) )
Cheers!
UPDATE:
As #carbonr noted You should add this line in viewDidLoad since iOS7+
self.edgesForExtendedLayout = UIRectEdgeNone;
self.tableView.contentOffset = CGPointMake(0.0, 44.0);
The above code does in fact work but it needs to run after the UITableView has finished creating all of its cells. I guess thats another question though.
You can set the initial bounds of the table view inside viewDidLoad, so the search bar appears hidden at the beginning.
You have to create the searchBar property and then use following code:
- (void)viewDidLoad
{
//...
CGRect bounds = self.tableView.bounds;
bounds.origin.y = self.tableView.bounds.origin.y + searchBar.bounds.size.height;
self.tableView.bounds = bounds;
//...
}
For others still looking for an updated solution, you can check out my answer over here.
Basically you need to update the contentOffset the first time viewDidLayoutSubviews is called.
I also have the same problem like yours. The following code solved my problem.Please add the code in you viewDidLoad() :
self.edgesForExtendedLayout = UIRectEdgeNone;
N:B: I used autoLayout in my project.
The iPhone SDK 3.0 has this handy new class "UISearchDisplayController" which makes it easy to create a search bar, handling all the user input and displaying the search results.
I am using it for my new app, but there is one thing i would like to change:
As a default, the search bar should be put at the top of the UITableView that displays the search results. So when scrolling down the result list, the search bar disappears.
What I would like to achieve is having the search bar always on top and when scrolling the TableView, the search bar should stay where it is. (Reason for this: in my app there are sometimes a lot of search results, so sometimes the user has to scroll down a while, and when he realizes that he has to change his search string, i don't want to force him to scroll all the way back)
What i already did is adding the search bar to the view of the UINavigationController which is the "parent view" of my table view, instead of adding it to the table view directly:
MyAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
searchBar = [[UISearchBar alloc] init];
searchBar.delegate = self;
[searchBar sizeToFit];
CGFloat searchBarHeight = [searchBar frame].size.height;
CGRect mainViewBounds = delegate.navController.view.bounds;
[searchBar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
CGRectGetMinY(mainViewBounds) + 20,
CGRectGetWidth(mainViewBounds),
searchBarHeight)];
searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[delegate.navController.view addSubview: searchBar];
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar: searchBar contentsController: self];
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;
... but here my problem is, that the table view stays behind the search bar, and there is always the first TableViewCell of the search results, that is hidden behind my search bar.
Is there a way to resize the UITableView of my UITableViewController permanently, so that it starts right under the search bar?
And there's another problem: Everytime i touch the search bar, the UISearchDisplayController automatically hides the Navigation Bar and resizes the UITableView (it expands to the top), so i think that at this point the UISearchDisplayController will have a big problem with my custom sized TableView...
Thanks a lot for any help!!
I don't have a solution off the top of my head - but I will say the concern you have seems to minimized by the ability for the user to simply tap the top of the screen and have the table zoom to the top (to change search terms if it's wrong).
My general solution for having bits on the page that I don't want to scroll, is to have the UITableView inside another view. That outer view contains two things -- a bar at the top, and a slightly-shorter-than-full-page table below it.
#interface:
UISearchDisplayController < UISearchBarDelegate > *searchDisplayController;
#implementation:
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar: searchBar contentsController: self];
searchDisplayController.delegate = self;
searchBar.delegate = searchDisplayController;
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;
Put this code in your TableViewController:
self.tableView.frame = CGRectMake(0,searchDisplayController?.searchBar.bounds.size.height,320,480);