As part of my application's design, I have placed an image inside of my UITableView's header.
This header image looks great, until the table is scrolled, moving the header relative to the position being scrolled to/from.
My question is, how do I stop this from happening? I'm assuming I'd have to do it another way, i.e. put a UIImageView above the UITableView so it has nothing to do with the scrolling. However, I cannot put a UIImageView outside of the UITableViewController.
How would I do this?
Create a view controller which has this view hierarchy:
view
\---> header view //set the frame to be the top 200 pixels or whatever you want
\---> table view // instead of being the top view, the table view is a subview with a frame starting below the header view
Set the tableview delegate and datasource and use them as normal
To solve my problem, I used a group tableview as their section headers scroll with the content and don't 'stick' under the navigation bar, i then stretched the tableview to an extra 10 each side, and pushed it 10 points to the left, 'getting rid' of the margins.
I then used custom tableview cells to design my own custom cells.
Related
I'm using a scroll view in the storyboard for one of my view controllers and I would like to know if there is a way to move the current view of the view controller down so that I can add things below.
I've seen that when tapping on CollectionView (which is at the bottom of my screen and extends below the view), the view on my viewcontroller seems to move down a bit to reveal more of the CollectionView, but not entirely. Is there a way that I can make the view go lower?
Change the size of viewController as shown in the image below:
If I use a UItableViewController it works fine but I need to use a UItableView inside a UIViewController instead. My question is, do i have to manually program it to add extra space at the top and bottom so the first and last cells won't be partially covered and how would I move the refresh indicator down so that its not covered?
Make sure your table view is added as the first subview of your view controller. This will ensure its scroll insets are setup properly.
Also be sure to set the table view's frame to match the bounds of the view controller's view and be sure to set the autoresizingMask to flexible width and height.
I've created a custom subclass of UIViewController that acts like a UINavigationController or a UITabBarController. Let's call it a ToolbarNavController. It has a toolbar at the bottom with controls for the user to move to a different content view.
I have two content views aside from the ToolbarNavController's view. Both are loaded from a nib and have their own controllers. The app starts out showing one of them. A button in the toolbar allows the user to switch between them.
When I add these views as subviews of the ToolbarNavController's views in viewDidLoad, they are correctly resized to fill the area between the status bar and the toolbar without overlap/underlap.
But when I try to lazy load the second view, adding it as a subview for the first time only when the user presses the toolbar button, iOS does not resize the view to account for the toolbar in its parent view, and it underlaps the toolbar which messes up my Autolayout constraints. Also, when I don't add the subview in viewDidLoad, if I put the device in landscape orientation before switching to the second view, it loads with a portrait orientation frame.
Bottom line: When inserting a subview in viewDidLoad, iOS sizes it correctly and manages autorotation for it. When inserting it later, I need to detect orientation set the frame myself. (And for some reason when I do this, autorotation kicks in again).
What is going on?
In viewDidLoad, the view is not yet layout for the resolution and interface orientation, and view properties are as they were in the interface designer. So, if you had a portrait view, that is how the initial properties of the view are set when going into viewDidLoad. When you add your view there, you add it to the XIB view. Later, iOS performs layout on the view hierarchy and thus resizes your inserted view as needed. But when adding your view at a later point, the view hierarchy has already been layout, so it is expected that the new view you are adding is also layout correctly.
Best practice is to calculate the size you need using the size of the view you are inserting into. For example, half the width of the containing view, or third the bounds, etc. This way it is independent on the orientation the interface is in.
I have a UITableView that I populate with cells in the normal fashion using the datasource and delegate. I would like to add a custom subview, that does the following:
1) scrolls with the UITableView
2) is seen beneath the UITableView scrollbar
3) can be moved and animated independently of any cell (acts as a selector that animates from one cell to the next)
I know how to animate a selector over the top of the UITableView, but that violates requirement #2 (it makes the scrollbar look terrible)
Has anyone seen an implementation of this, or know the proper way of doing it?
Did you try something like this?
Have a base view.
Add your custom subview to the base view.
Then add your table view on top of it to the base view.
Implement the table's scroll delegates and move the custom subview.
Thinking at the top of my head, couldn't you disable the scrollbar for the table view and place a transparent scroll view with the same dimension as the table view on top. You're effectively using the scroll bar of the scroll view instead of the table view. You'd scroll the scroll view in step with the table view.
I'm building an iPhone application and in one of my problems, I am trying to resize sub views. First, I have a Table View that when each data is tapped, it opens a new view. But the problem is that images and text in that opened view (which contains a Navigation Controller) is not aligned properly. They are all misplaced and my guesses is that on that view, it's only showing 3/4 of the top, not the whole view (which most of my images at the bottom are only showing half of the image). My goal is to fit every image and text to fit into my view that contains a Navigation Controller at the top of my view. So after researching, I can change the size and position in Interface Builder, but for some reason they are blank which I can't edit:
In addition, I tried this code in my viewDidLoad:
// DetailViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.view.autoresizesSubviews = YES;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
So far none of these are even resizing my view to fit with my navigation controller, so I hope someone has a better idea how to resize and fit my view with Navigation Controller, thanks
Let me summarize, so I get what you're trying to do here. You have a view with a UITableView. When you select a cell in that table view, you push a new view onto the navigation stack. In that new view, parts of your layout are obscured at the top by the navigation controller's nav bar?
Assuming I'm right...
You're issue is with the autoresizing mask of the view (and subviews) of the view that is being pushed onto the navigation stack. You'll need to set it in Interface Builder to see the correct results. It should look like this:
This means that the view will shrink and grow to match any size constraints that it finds itself under. In the case of being shown in a UINavigationController, it will shrink itself so that it fits in the smaller screen space between the nav bar and optional toolbar.
Take care to also set appropriate autoresizing masks on all of the subviews of this view as well, such that they all handle arbitrary resizing appropriately.