Working with UIScrollView and UICollectionView - ios

In my project, I'm trying to do an app similar to Instagram where I can scroll endlessly on the images that I have inside my personal profile. While scrolling, the top portion of my profile details is above where the whole screen will be filled with my photos when continuously scrolling thru my photos.
I think the way to achieve this is using UIViewController and working with UIScrollView and UICollectionView. However, my issue here is how do I create a custom height of the UICollectionView or UIScrollView in order to show the proper or exact height of the View? As such, I do not want to see "white spaces" at the bottom, or "cut" pictures.
I've tried using let height = CGRectGetHeight(self.myCollectionView) to get the height, but it always return me with the height I fixed in my IB regardless the number of items I have.
Could someone share with me the structure how I should do it? Many thanks!

Related

UIImageView streches over entire row height of UITableViewCell

Intro: Hi, I'm working on a "News" app, that uses a news API online. I want to display the content of the latest news in a TableView (Currently I want to display the title of the news item, the name of the organization that posted it (e.g: the BBC), and an image that I load from a given link). I dragged a table view in the Main storyboard, created a custom cell for a singular news item, and get all of the required information from the internet.
The Problem:
When all the data gets loaded into the TableView, the image streches across the whole rows height.
I'm trying to find a work-around for hours now. At the moment, In the prototype cell, I have a Stack View, that contains 2 labels and an ImageView, with a Vertical Axis, and a Distribution of Fill Equally.
There are no constraints on the Views inside the Stack View (the 2 labels and ImageView), and I'm not editing any constraints within the code, to keep it as simple as possible.
I also tried the constraints approach prior of using the stack view, but it gave the same result.
Image Of The Stack View
The Result in the Simulator (Rows without an image, don't have an image url provided by the api, so I just skip them).
I tried being as expressive as I can about the problem, if you are still missing some information please let me know
The problem you are encountering is due to constraint issue. The problem should be solved by unstacking the view and put constraints instead.
You can still achieve scalable application using them.
If you are confused with how to do it, refer https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithConstraintsinInterfaceBuidler.html
https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/AnatomyofaConstraint.html
These should help.
I think you are in right Direction.
if you want static(fixed) Layout Follow below step.
change StackView Distribution from Fill equally to Fill
Apply StackView(leading,trailing,top,bottm) =
cell(leading,trailing,top,bottm)
set tableView rowHeight to 300 or whatever you want
if you want dynamic layout follow below step
https://www.raywenderlich.com/1067-self-sizing-table-view-cells

Stretchy header view for UICollectionview and minimize UIImageView while scrolling up

I am trying to achieve a certain layout that looks like twitter and many other apps. Some people do it in UIVIewLayouts but I want to achieve it using this way (if possible ). As you see in the attached image. I have Header, and cells in the collectionview.
While scrolling up I want to minimize the imagview avatar inside the headerview. -> ( ViewForSupplementaryEelementHeader )
while scrolling down, I want to make the top UIImageview to be fixed to the top and stretchy
Thank you all in advance
*ps I am doing all of this in code nothing with storyboard and I dont want to use it at all.
Please advise me how to access these imageview while scrolling up and down.
I think this is the example you are looking for
https://github.com/sunlubo/StretchyHeaderView
This will add only tableview in storyboard...other all the work is done through coding

Instagram Profile UIView structure

I'm trying to create an Instragram profile page-like view in iOS swift, but I don't know what and how you should go about making one! So, I'm guess you should use UIScrollView in the ProfileViewController, and embed UICollectionView for the pictures. But, isn't UICollectionView itself a subclass of UIScrollView? As far as I know, overlapping two scrollView is not a good practice.. Any recommendation? I want to have a profile picture on the top with name and caption right underneath the profile picture. And, a collection of pictures(column: 3) on the lower portion of the ViewController. Number of pictures are variable, so I need the ViewController scrollable.

Xcode UITableView image does not align properly on simulator

I am working on a project on Xcode7.3 using swift using autolayout. I am stuck with an problem with the UITableview not displaying properly on the simulator.
I created a ViewController and dragged a TableView into ViewController. Then I dragged a UIView and UIImage ontop of that TableView (To display as a header image). I also dragged a UIImage onto the prototype cell. They are all aligned in the center horizontally and vertically. However, when I run the app, they don't show in the middle of the screen.
As shown in the UITableView_Problem Image, the images are offset to the right. What is also weird is that when I rotate the screen, the scrollbar on the right does not go all the way to the right. The images appears to be in the center of the screen if I consider where the scroll bar is the end of the screen. But that doesnt make sense because the bottom bar items spans the full width of the screen.
However, if I create a UITableViewController from the story board instead of dragging a TableView onto a ViewController, I do not have a problem at all. (Image3)
It is frustrating because I wanted to add a text field for keyboard at the bottom of the screen just like the comment section in Instagram app. And after hours of searching, it appears that the only way to do that is to drag a tableView onto a ViewController. i stack imgur com JC5Pw png
Could anyone please assist? Much appreciated
Blockquote
note: I dont have a developers account yet so I cant check on an actual device
You are designing your interface in the wRegular/hRegular (or universal) size class. You will need to be very good about your constraints or develop a layout for the wCompact/hRegular size class for iPhones in portrait mode. You can change this by selecting here the blue part on the bottom of your storyboard
Thanks Dan for your prompt response! I added constraints to everything except for the tableView. Dont know what I was thinking as I have been troubled by this bug for a few days. Everything works fine after the tableView constraints was set!

UIPageControl or Horizontal UICollectionView?

I am looking to achieve a similar effect to the Netflix app where at the top they have a scrollable header displaying different 'featured' movies.
As soon as the header start to scroll and the next image enters the view it downloads the image, also while being scrolled if you let go it snaps into place the image that was currently being shown the most.
I am not sure how to proceed and try to solve this problem. Any suggestions? should I look at using UIPageControl, or should I use a horizontal UICollectionView?
Thanks
You can implement it by using a horizon collection view,it can help you handle the reuse of imageViews!Or you can use a UIScrollView to contain a couple of subViews to display the image or three subViews and switch the image content

Resources