I use Tableview to show library songs and songs play on did select cell,
when song play mini player popup on bottom.
At that time last cell of table view is not show properly, some of its portion hide behind mini player so please suggest.
Thanks
Try to set contentInset
tableView.contentInset = UIEdgeInsetsMake(0, 0, 110, 0); values are - top, left, bottom, right // change as per your needs
OR
- (void)viewDidLayoutSubviews {
CGFloat navbarHeight = 44; // this is supposed to be 64 but you should dynamically calculate it or better use constraints
CGRect tempFrame = self.view.frame;
self.tableView.frame = CGRectMake(tempFrame.origin.x, tempFrame.origin.y, tempFrame.size.width, tempFrame.size.height - navbarHeight);
}
A quick fix can be to add a footer View to your tableview. make the footer view height the same as your mini player. customise the footer view to your needs or make the footer view background colour to clear so it will not be visible.
Related
I have created a tableview in code as follows:
_myTableView = [[UITableView alloc] initWithFrame:
CGRectMake(160, 80, 140, 100) style:UITableViewStylePlain];
_myTableView.delegate = self;
_myTableView.dataSource = self;
_myTableView.scrollEnabled = YES;
[self.view addSubview:_myTableView];
It largely works as it should with the following exception. Because the results in the table vary, I manually adjust the height of the tableview so that it only takes up as much space as the returned rows need as follows:
-(void) changeTVHeight: (float) height {
//height calculated from number of items in array returned.
CGRect newFrame = CGRectMake(120, 80, 180, height);
self.myTableView.frame = newFrame;
}
This works great for shrinking the tableview if there aren't that many results.
However, if there are a lot of results, the tableview expands below the visible part of the screen or the keyboard. In this case, I would like to be able to scroll the Tableview to see the lower rows.
scrollEnabled is set to YES.
But while it does allow one to scroll a bit, the scroll is resisted so with effort you can scroll a little bit but due to rubber band effect you cannot get further than a few rows below the screen and you cannot tap on the lower rows.
I am using autolayout in storyboard for much of the screen. The overall screen scrolls fine but this merely moves the tableview anchored to the screen up and down. There are no constraints on this tableview but it is added as a subview of the view.
My question is how can I make the tableview scrollable so that it scrolls without resistance?
Thanks in advance for any suggestions.
Edit:
I tried adding the tableView to self.scrollView instead of self.view. This anchored the tableView to the scrollview so it is possible to scroll the whole screen down and see the bottom of the tableview. However, this is not ideal because the rest of the screen is empty way down and you can't see the context for the tableview. (It's an autocomplete for a textfield at top of screen.)
In contrast when the tableview is added to self.view, it is in correct place, it semi-scrolls or bounces. It just doesn't scroll down to where I need it to scroll.
You need to set a limit so that the table view cannot be larger than the view itself. Tableviews are built on UIScrollView and will handle scrolling on their own, you don't need to try to size it manually. The reason the table view bounces but doesn't scroll is because it is extending below the bottom of the screen. It wont scroll because it has already scrolled to the bottom, you just can't see it because it's outside of the superview.
-(void) changeTVHeight: (float) height {
CGFloat limitedHeight = MIN(height, self.view.frame.size.height)
CGRect newFrame = CGRectMake(120, 80, 180, limitedHeight);
self.myTableView.frame = newFrame;
}
I'm trying to replicate the following GIF from Postmates checkout - a scrollable UITableView positioned on top of a MapView. This tableview can be scrolled, with the normal bounce effect if I go too far down or up.
Currently, I have the MapView and UITableView added as sibling views to my ViewController's view. I have adjusted the frame of the table view to move it down.
CGRect rect = CGRectMake(
0.f,
200.f,
self.view.bounds.size.width,
self.view.bounds.size.height - self.navigationController.navigationBar.bounds.size.height - 200.f
);
The two main issue's I'm having are:
I cannot figure out how to drag the entire tableview down when pulling down. E.g. the grey (my tableView.backgroundColor) sticks when I scroll down. If however, I make that background clear, then when I drag up, you see the map emerging from behind the view.
My cells keep disappearing when I scroll up. I have clipsToBounds = false, and I'm not actually dequeuing cells, just creating them in my cellForRow method, but they still disappear.
I feel like this should be a straightforward layout, but I'm missing something!
I've tried adjusting the contentInset of the table view, but then the scrollbar does not align with the cells as it does in the gif and does not look nice.
We needed similar effect in our app, along with parallax in the underlying view(map here/ we had a photos gallery).
I assume you want something like shown on this blogs video here
I wrote a small blog on how to achieve this. You can find this here
Basically its just a play of contentInsets and contentOffset properties of UITableView
If this does not suits you, here my suggestion in your two main points.
Controller's View has subviews
Map View (fills complete super view)
UITableView (fills complete super view) and in code set content insets.top = kHeightOfVisibleMap
The solution was simpler than I thought, no autolayout or crazy weird tricks required.
Add a full screen table view to your controller, and insert a full screen map view behind it.
self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
[self.view insertSubview:self.mapView belowSubview:self.tableView];
Add a dummy view with the background color of your table view with a height of around 200 pixels, and a full width, into the tableFooterView on your table view.
CGFloat footerHeight = 200.0;
UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, footerHeight)];
dummyView.backgroundColor = [UIColor whiteColor];
self.tableView.tableFooterView = dummyView;
Set the content offset of the table view to be the inverse of that footer view's height:
CGFloat footerHeight = dummyFooterView.bounds.height;
self.tableView.contentOffset = CGPointMake(0, -footerHeight);
Set the content inset of your table view to offset the footer view.
self.tableView.contentInset = UIEdgeInsetsMake(footerHeight, 0, -footerHeight, 0)
Adjust the scrollbar position, again, based on the footer's height.
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(footerHeight, 0, 0, 0);
This will push down the tableview, ensure the scroll bars match the table view, but allow it to bounce 'up' above its initial position and will ensure the background does not peek through the bottom of the tableview.
I build a UITableView with section header that can expand a specific section. I am using a custom view from a .xib file for a UITableViewHeaderView. I want to set margin values of the HeaderView so that it is not full width and stays on top when scrolling down (not full height).
As you can see in the animation the view has full width - is it possible to add a margin to the header that there is some space between the HeaderView and the edge of the screen.
I want to reduce the height of the sticky header if the UITableView is scrolled - so that there is just the text of the button visible on top of the screen. I have implemented the following delegate command from UIScrollView which works fine, but it reduces the margin for the first HeaderView so that it moves behind the navigation bar (see in animation) - how can I avoid that?
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat sectionHeaderHeight = 20;
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
You could put a subview with a margin in your headerview.
Setting the height is certainly possible and is done by setting the frame, but you could also make your navigation bar non-translucent, which would save you a ton of coding.
[self.navigationController.navigationBar setTranslucent:NO];
If you want to change the height, your code would look something like:
CGRect frame = header.frame;
frame.size.height = 44;
header.frame = frame;
[self.tableView setTableHeaderView:header];
I'm very new to iOS. I have a UITableView that filled with many custom cells, but the bottom cell is is not visible properly when scroll down.my Y value of the UITableView is 44 and Height is 480. Only the half of the last cell is visible when scroll down. How can I fixe this problem.
Thanks in advance.
Use -
tableView.contentInset = UIEdgeInsetsMake(0, 0, 120, 0); //values
passed are - top, left, bottom, right
Pass bottom offset as per your needs.
it is because you set your tableview's frame wrong, if your view has a navigation bar , usually use this code:
CGRect frame = self.view.bounds;
frame.height -= 44;
44 is the height of your navigation bar.
If you have a status bar visible on the top, then it will occupy 20px which will push down your tableView by the same. To avoid this, make the tableView height 460 instead of 480.
For me this is worked.
I have commented out my code
-(void)viewWillLayoutSubviews
{
dispatch_async(dispatch_get_main_queue(), ^{
//This code will run in the main thread:
CGRect frame = tableViewObj.frame;
frame.size.height = tableViewObj.contentSize.height;//commenting this code worked.
tableViewObj.frame = frame;
});
}
That's it. It worked for me. Please make sure you have not changed tableview frame some where while in implementation file.
If you are on iOS7 and using a navigation controller toolbar, make sure to set it to translucent:
self.navigationController.toolbar.translucent = NO;
I am building an app with a stream of social content and am trying to get the behavior of how instagram does it's stream in app. So basically a top header that scrolls off the screen but bounces between that and the content. I can make the top header scroll off the screen and I can make the view not bounce but I want to use Pull to refresh and that ends up going above the "faux" nav bar UIView. I know that a normal Navbar will produce this but this one that scrolls off is a different story.
Currently I have a UITableview that has a UIView above the UITableViewCell and everything works great except the bounce happens above the UIView. I figure I need to get the UIView above the UITableView however in the UITableViewController the storyboard won't allow me to place the UIView above the UITableView.
Any ideas???
Thanks
Well I finally got this all to work so I thought I would post the Answer for everyone.
Basically I set a standard Navigation bar and then on scrollViewDidScroll I get the offset of the scrolling and change the frame based on that. This seems to work perfectly, see below for my scrollViewDidScroll method.
- (void)scrollViewDidScroll:(UIScrollView *)sender {
//Initializing the views and the new frame sizes.
UINavigationBar *navbar = self.navigationController.navigationBar;
UIView *tableView = self.view;
CGRect navBarFrame = self.navigationController.navigationBar.frame;
CGRect tableFrame = self.view.frame;
//changing the origin.y based on the current scroll view.
//Adding +20 for the Status Bar since the offset is tied into that.
navBarFrame.origin.y = MIN(0, (sender.contentOffset.y * -1)) +20;
navbar.frame = navBarFrame;
tableFrame.origin.y = MIN(0,MAX(-44,(sender.contentOffset.y * -1)));
tableView.frame = tableFrame;
}
Also you will want to make your TableView 44px taller to compensate for the scrolling otherwise your frame will not be big enough. I just did this in viewWillAppear and made the frame bigger.