UICollectionView: What is the difference between contentSize and bounds? - objective-c

What is the difference between:
self.collectionView.contentSize.height and self.collectionView.bounds.origin.y?
The latter always seems to be smaller than the former?
Any clarifying sketches would be highly appreciated.

contentSize is the size of the content, which is shown by scrolling. say you have 10 cell's sizing of 3600x1200. Then the content size will be 3600x1200. Bound will be the actual frame of the collectionview.
For more information
contentSize is not direct property of UICollectionView. It's derived from the UIScrollView. check here
happy coding.

The value of self.collectionView.bounds.origin.y is 0. Because the bounds of an UIView is the rectangle which is expressed by its own co-ordinate system.
Refer to Cocoa: What's the difference between the frame and the bounds?
self.collectionView.contentSize.height = contentSize of scrollview
Let you have a collection view(scroll vertically) whose frame is (0,64,320,504) and size of its each cell is (100,100) and you have 20 item. So, each row of collection view contain 3 cell. Now, to fit 20 item in collectionview 7 row will generate and we can see all those item by scrolling vertically.
Actual size of collectionview is (320,504) and the contentsize is (320,700).
Note:Assuming collectionview is scrolls vertically and there is no space between two row.

Related

Use Page Width when printing NSTableView instead of the view width

This seems like it should be simple...
I have a basic NSTableView in a window. The window is arbitrarily resizable (width + height). The tableview is pinned to the edges of the window and it has a single column that contains view-based table rows. The table rows have content pinned to the left and right edges of the cells, so as you resize the width of the window, you are effectively adjusting how much white space is in the middle of the cell.
I'm now trying to implement printing for this tableview. When I set up the NSPrintOperation, I'm passing my tableview subclass as the view to print. My desired result is this: I want the width of the tableview to be resized to the width of the page (regardless of how wide the window is right now on screen). I don't want to adjust the scaling factor (because that affects width + height) - I simply want the result to be as if I manually resized my window to exactly match the width of a printed page and then hit "print".
I've tried setting horizontalPagination to .fitPagination - but the problem there is that seems to apply a scaling factor to the width + height (which means if the window is currently "very wide", it makes the row height really small as it compensates for the width).
I've tried overriding adjustPageWidthNew:left:right:limit: in my tableview subclass - but that never gets called.
I suppose I could create a duplicate tableview and re-set it up exactly like the one I have on screen, but that feels like overkill when the view I want is already good to go - I just need to temporarily resize the width while I'm printing.
Any ideas?

custom view-based nstableview resizing

I have an NSView class, which draws it's contents on a CALayer. These NSView classes are held in an NSTableView which has a single column. I need to make it so the NSTableView adjusts it's size to fit the contents of the NSViews it contains, which can have variable widths, i.e. the NSTableView needs to have the same width as the widest cell. This in turn will allow the user to scroll if the cells' widths are larger than the available area.
Think of it like a multitrack audio editor, where each view is a track, but the tracks can have different lengths.
At the moment, the NSView cells seem to adjust width automatically to the size of the table column, so I can see two possibilities: One is to make it so the cell NSViews set their width, and somehow have this promulgate everywhere else. The other is to have the tableview or nstablecolumn set its width based on the maximum width. I have tried setting the NSTableColumn width and minWidth, but this doesn't seem to work (it doesn't always adjust to the correct size, if the size is big).
Any suggestions or help to make this work?
If you're using CALayer (lets call it root layer) to draw the view contents, try to create another CALayer which will be a child of the root layer (this would be the audio track). You can set the size of the child layer independently and also you will know which one is biggest.
Root layer will always be as big as the table view, as you said:"NSView cells seem to adjust width automatically to the size of the table column" - don't try to change root layer size, but child layer size.
Once you determine the widest child just change table view frame to be the same width.

Change UIImageView height while scaling down to specific width

I have a UIImageView inside a UIScrollView.
What I am trying to achieve is to have a flexible height for the UIIMageView depending on the image that is loaded in while keeping the width of the UIImageView the same.
I also don't want the UIImageView to scale from the centre, but rather from the top most point.
Any help is greatly appreciated.
Thanks,
Ashey
First of all, adjusting the height of a UIView (or any of its subclasses) will adjust the height from the origin.y coordinate downwards. It doesn't span from the center.
Do you know the sizes of your image beforehand? If the images appear in the same order each time, you can just supply the sizes in an array.
If you do not know the sizes, or the order of the images, you can use the size property on the UIImage you are putting in your UIImageView. This will return to you a CGSize, of which you can take the height. You will also need to update the contentSize of the UIScrollView.

How to make a side-scrolling object?

I would like to make a side-scrolling object that is only 200 pixels wide and 50 pixels tall. This side-scrolling object would contain five different objects that, when scrolled into the middle, act as if selected. How could I go about doing this?
I want sort of the same effect that the iPhone home screen has where it latches on to a page when you slide it. Instead of latching on to the pages though, I want it to latch on to my five different objects.
The side-scrolling behavior is achieved with a UIScrollView with pagingEnabled set to YES. Set the scroll view's width to the size of your pages. Your scroll view delegate can calculate which object is on screen by dividing contentOffset.x by the scroll view's width.
If you want to show several items on the screen at once but still page between the individual items--think of the way the iWork apps show multiple documents, for example--there are three steps involved:
Set the scroll view's width to the width of the objects, not the width of the screen.
Set the scroll view's clipsToBounds property to NO so it displays the objects that aren't within the scroll view's frame.
Subclass UIScrollView and override -pointInside:withEvent: to return YES if the point is within the area you want to respond to touches within. (For example, if you want to respond to touches within the entire width of the screen, just ignore x and make sure y is between the top and bottom of the view.) Use this subclass instead of a standard UIScrollView.

Way to return bounds of non-hidden elements in UIView

Right now, I have a UIScrollView which scales its UIView contents on zoom events. When I hit a certain zoomScale threshold, I want to be able to toggle on and off extra information within the UIViews. Right now, I am simply setting the hidden flag to YES/NO to accomplish this.
However, a problem occurs while attempting to get the bounds of the UIView. The bounds always returns a width and height that extends to include the invisible content.
Is there a way to limit the bounds to only return the size of visible content within a UIView?
You could derive new bounds as you zoom and not rely on the view's automatic bounds adjusting.
OR
If it doesn't make your code too complicated, I would remove those subviews from your resizing view instead of just hiding them.