I'm using storyboard to create a details view. I have a UITabViewController, which then goes to a UITableViewController, then to my MessageDetailsViewController, which is a subclass of UIViewController. My controller's main view also has a UIScrollView subview, which contains all of my elements as subviews.
In storyboard, my layout has the navigation bar at the top, and the tab bar at the bottom.
I resized the UIScrollView to fill the full parent view, going behind the tab bar and navigation bar.
I set up some static subviews in the scroll view, then I add a bunch of extra labels to the scroll view dynamically in a for loop. In the simulator, the labels are showing up where I'd expect them to, but I cannot get the view to scroll. I'm setting the scroll view's content size with:
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width, y);
Where y is the frame.origin.y + frame.size.height + VerticalBuffer of the final item (it shows up as 1200+ in my log message, so it's getting calculated properly).
What am I missing to make it scroll properly?
Related
I have a UIScrollView for which I have a UIView which is the subview of the scroll view , the UIView has a lot of other subviews and I am getting the height for it dynamically after adding the subviews , this is my piece of code to add the view to scroll view
CGRect frameOfView = CGRectMake(0, 0,Get_Bounds.width, globalYPosition);
self.parentProductDetailView = [[UIView alloc]initWithFrame:frameOfView];
I am first initialising the view this way and then after adding all subviews I am doing this,
frameOfView.size.height = globalYPosition;
[self.parentProductDetailView layoutSubviews];
self.parentProductDetailView.frame = frameOfView;
[self.productDetailScrollView addSubview:self.parentProductDetailView];
self.productDetailScrollView.contentSize = CGSizeMake(0, self.parentProductDetailView.frame.size.height *1);
But my scrollview does not scroll properly it either sticks to top or bottom.
Here globalYPosition is the sum of height of all subviews added to parentProductDetailView
The procedure you used seems correct. No matter the subviews your scroll view should scroll properly by simply using a larger content size then its frame size.
The scroll view may stick, snap to some points if paging is enabled which is what is happening in your case. If the content view is larger then 1.5th of the frame size then the scroll view will snap to top/bottom or left/right. If it is smaller then it will only snap to starting position.
This may be very useful for situations like having a side menu that takes a part of a screen but in your case you should simply disable the paging and scrolling should work fine.
I have a view controller that has a button at the top center, and a view underneath which will have the collectionview inside. I want this collectionview to scroll separately to the top view (so it scrolls underneath that top section).
This works fine but the view with the collectionview doesn't reach the bottom. You can see in the screenshot I gave the superview a red background - the collectionview doesn't reach to the bottom of the view. All the constraints are fine.
It works if I uncheck "Autoresize subviews" in the Interface Builder for the UIView inside the View Controller but this then makes all the cells and any navigation bars I add inside that view 1000px wide. Why is my view being shortened - and how can I get the best of both these scenarios? A View that hits the bottom of the screen and all the cells/navigation bars the width of the view?
Constraints for the view:
Constraints for the collectionview:
I did have a tab bar too, and the gap is the exact height of my tab bar.
Anyway I fixed this by putting:
self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeBottom;
in viewDidLoad method.
I have the following problem:
I have a Scrollview with Autolayout top,left,bottom,right is set on 0, in this ScrollView is a ContentView also set everything on 0. The ContentView contains a ImageView a Segmented Control and a UIView which is connected to 2 different UIViewController.
The UIView is set top 0 to the Segmented Control and to bottom 0 to the contentView.
My Problem is that the UIView in the ContentView is not streets to the bottom of the ContentView. How can i solved this Problem?
Picture 1:
Storyboard UIViewController with ScrollView
Picture 2:
View on an iPhone 6 Plus
Here there are the size inspector constraints pictures:
ScrollView
MainView of Controller
ContentView in ScrollView
UIView in ContentView
Seems like the problem is in scroll view bottom content inset. By default scroll view have automaticallyAdjustsScrollViewInsets property enabled, and if you insert scroll view as nearest view to tab bar (as I can see at screenshot), bottom inset will set as nonzero (this used for show content under transparent tab bar while scrolling). But for use this behavior properly, you should connect scroll view bottom to view (root view) bottom, not to bottomLayoutGuide. Second option - disable automaticallyAdjustsScrollViewInsets property and handle contentInset and scrollIndicatorInsets properties of scroll view manually (set them to UIEdgeInsetsZero if you don't want change your constraints).
I have a UIImageView on my ViewController, I also placed a CollectionView below it in storyboard. I populate the collectionView and with data and when I run the app, only the collectionview section scrolls, while the image view remains static on the page even while scrolling through the list of collectionView items. I wan the whole screen content to scroll up when the top item of collectionView is reached. How do i do this in objective-c. If it will be with a scroll view, how do ii implement this?
Images below illustrate how it is on iPhone music app in the radio tab section, which contains banner and collection view below, when i scroll up the banner moves out of sight above, and the collection view appears and the remaining content. that's what i want, the banner shouldn't be static
Have a UIScrollView as a parent for for image view and collection view. And your image view and collection view inside the scrollview. Now set contentSize property of the parent scrollview.
var size : CGSize
let height = imageView.frame.height + heightOfCollectionView // heightOfCollectionView is height calculated from total number of cells/sections present in collection view
size = CGSizeMake(self.view.frame.width,height) //assuming
scrollView.contentSize = size
Set this is viewDidLayoutSubviews of your view controller
By looking at the screenshots you can create a collectionview cell just to present that image view and put that cell at the top.
I am developing an iOS application, and I want to add a search button that initiates a search of a table view. When searching, the search bar should not be scrolled with the table cells.
To make a search bar (or any view really) "stick" to the top or bottom of a UITableView there are two approaches:
Adjust the frame of the table to be the view height minus the height of your bar, and then set the bar's frame to {0, 0, CGRectGetWidth(self.tableView.frame), CGRectGetHeight(self.tableView.frame)}, which would position it statically at the bottom of the view. If you are using a stock UITableViewController, you'll need to do some additional work because self.view and self.tableView both point to the same object. You'll need to set a new UIView to self.view which will then be the container for the table view and your search bar view.
Add the bar as a subview of table, then implement UIScrollViewDelegate in your controller and use scrollViewDidScroll: (which fires whenever the user scrolls the view) to update the bar's position. The new position would be something like:
CGRect adjustedFrame = self.searchBarView.frame;
adjustedFrame.origin.y = self.tableView.contentOffset.y + CGRectGetHeight(self.tableView.frame) - CGRectGetHeight(self.searchBarView.frame);
self.searchBarView.frame = adjustedFrame;