Re: Put UICollectionView within UITableViewCell
I’ll give it a shot, thank you very much > On 10 Mar 2018, at 10:27 AM, Cosmo Birchwrote: > > But you presumably know the width (i.e. the CollectionView width minus any > insets), and you can calculate the height based on that with NSString or > NSAttributedString boundingRect functions. Assuming you have a subclass for > your CollectionViewCell, you can add a method to return your cell height > based on its contents layout. > >> On Mar 9, 2018, at 8:21 AM, Gary L. Wade >> wrote: >> >> @Cosmo >> >> My collection items contain label, so I don’t know the exact sizes before >> hand. >> > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/heyhgl%40gmail.com > > This email sent to hey...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Put UICollectionView within UITableViewCell
But you presumably know the width (i.e. the CollectionView width minus any insets), and you can calculate the height based on that with NSString or NSAttributedString boundingRect functions. Assuming you have a subclass for your CollectionViewCell, you can add a method to return your cell height based on its contents layout. > On Mar 9, 2018, at 8:21 AM, Gary L. Wadewrote: > > @Cosmo > > My collection items contain label, so I don’t know the exact sizes before > hand. > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Put UICollectionView within UITableViewCell
@Cosmo My collection items contain label, so I don’t know the exact sizes before hand. @Gary In my case I actually also need to display section headers and section index titles, so using just a collection view probably won’t be easy I guess. — From the suggestions it seems it might be something very difficult to pull off. I wonder if anyone ever reverse-engineered multiline UILabels to see how table cells can have correct heights containing them. > On 10 Mar 2018, at 12:14 AM, Cosmo Birch <minonom...@gmail.com> wrote: > > Where I work we have spent a fair amount of trying unsuccessfully to get > self-sizing collection view cells to work as described by Apple documentation > with UICollectionViews that have any sort of complexity. I would suggest > trying to implement the sizeForItemAtIndexPath delegate method to see if that > solves your problem. Sorry if the name of the method is slightly off. I can’t > look it up at the moment. > >> On Mar 9, 2018, at 8:00 AM, Glen Huang <hey...@gmail.com> wrote: >> >> Hi, >> >> I asked a question about putting UICollectionView within UITableViewCell on >> Apple Developer Forums (https://forums.developer.apple.com/thread/98176), >> but it doesn’t get many replies. I’m not sure if it’s ok to repost the >> question here. I apologize if it’s not. >> >> Here is the question: >> >> Hi, I'm trying to create a table view with cell content like this >> >> | Label | >> | CollectionItem 1 CollectionItem 2 CollectionItem 3 | >> | CollectionItem 4 | >> >> Collection view item should auto wrap at cell end, both the collection view >> and table view use automatic height. >> >> I can somewhat achieve this effect by doing: >> put the label and the collection view in a vertical stack view, make the >> stack view's each edge touch table cell's corresponding edge. >> disable collection view scrolling. >> collection view's intrinsicContentSize returns layout's >> collectionViewContentSize value. >> in table cell's prepareForReuse method, I make the collection view reload >> its data. >> >> But the problem comes when each table cell can contain different number of >> collection items: some table view cells have incorrect heights, clipping its >> collection view. My guess is that when table cells get reused, they don't >> take collection view's new intrinsicContentSize into account. >> >> I tried calling sizeToFit/layoutIfNeeded/updateConstraints in cell's >> prepareForReuse method, none of them works. >> >> If I replace the collection view with a multiline label, and make each cell >> contain different length of text, the cells all have correct heights. >> >> I wonder why label are able to correctly resize cells? how can I make >> collection views do the same? >> > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Put UICollectionView within UITableViewCell
I would suggest rethinking the table view enclosure and just use a collection view with headers and footers by way of the supplemental views. -- Gary L. Wade http://www.garywade.com/ > On Mar 9, 2018, at 8:00 AM, Glen Huang <hey...@gmail.com> wrote: > > Hi, > > I asked a question about putting UICollectionView within UITableViewCell on > Apple Developer Forums (https://forums.developer.apple.com/thread/98176), but > it doesn’t get many replies. I’m not sure if it’s ok to repost the question > here. I apologize if it’s not. > > Here is the question: > > Hi, I'm trying to create a table view with cell content like this > > | Label | > | CollectionItem 1 CollectionItem 2 CollectionItem 3 | > | CollectionItem 4 | > > Collection view item should auto wrap at cell end, both the collection view > and table view use automatic height. > > I can somewhat achieve this effect by doing: > put the label and the collection view in a vertical stack view, make the > stack view's each edge touch table cell's corresponding edge. > disable collection view scrolling. > collection view's intrinsicContentSize returns layout's > collectionViewContentSize value. > in table cell's prepareForReuse method, I make the collection view reload its > data. > > But the problem comes when each table cell can contain different number of > collection items: some table view cells have incorrect heights, clipping its > collection view. My guess is that when table cells get reused, they don't > take collection view's new intrinsicContentSize into account. > > I tried calling sizeToFit/layoutIfNeeded/updateConstraints in cell's > prepareForReuse method, none of them works. > > If I replace the collection view with a multiline label, and make each cell > contain different length of text, the cells all have correct heights. > > I wonder why label are able to correctly resize cells? how can I make > collection views do the same? > > Thanks very much. > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Put UICollectionView within UITableViewCell
Where I work we have spent a fair amount of trying unsuccessfully to get self-sizing collection view cells to work as described by Apple documentation with UICollectionViews that have any sort of complexity. I would suggest trying to implement the sizeForItemAtIndexPath delegate method to see if that solves your problem. Sorry if the name of the method is slightly off. I can’t look it up at the moment. > On Mar 9, 2018, at 8:00 AM, Glen Huang <hey...@gmail.com> wrote: > > Hi, > > I asked a question about putting UICollectionView within UITableViewCell on > Apple Developer Forums (https://forums.developer.apple.com/thread/98176), but > it doesn’t get many replies. I’m not sure if it’s ok to repost the question > here. I apologize if it’s not. > > Here is the question: > > Hi, I'm trying to create a table view with cell content like this > > | Label | > | CollectionItem 1 CollectionItem 2 CollectionItem 3 | > | CollectionItem 4 | > > Collection view item should auto wrap at cell end, both the collection view > and table view use automatic height. > > I can somewhat achieve this effect by doing: > put the label and the collection view in a vertical stack view, make the > stack view's each edge touch table cell's corresponding edge. > disable collection view scrolling. > collection view's intrinsicContentSize returns layout's > collectionViewContentSize value. > in table cell's prepareForReuse method, I make the collection view reload its > data. > > But the problem comes when each table cell can contain different number of > collection items: some table view cells have incorrect heights, clipping its > collection view. My guess is that when table cells get reused, they don't > take collection view's new intrinsicContentSize into account. > > I tried calling sizeToFit/layoutIfNeeded/updateConstraints in cell's > prepareForReuse method, none of them works. > > If I replace the collection view with a multiline label, and make each cell > contain different length of text, the cells all have correct heights. > > I wonder why label are able to correctly resize cells? how can I make > collection views do the same? > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Put UICollectionView within UITableViewCell
Hi, I asked a question about putting UICollectionView within UITableViewCell on Apple Developer Forums (https://forums.developer.apple.com/thread/98176), but it doesn’t get many replies. I’m not sure if it’s ok to repost the question here. I apologize if it’s not. Here is the question: Hi, I'm trying to create a table view with cell content like this | Label | | CollectionItem 1 CollectionItem 2 CollectionItem 3 | | CollectionItem 4 | Collection view item should auto wrap at cell end, both the collection view and table view use automatic height. I can somewhat achieve this effect by doing: put the label and the collection view in a vertical stack view, make the stack view's each edge touch table cell's corresponding edge. disable collection view scrolling. collection view's intrinsicContentSize returns layout's collectionViewContentSize value. in table cell's prepareForReuse method, I make the collection view reload its data. But the problem comes when each table cell can contain different number of collection items: some table view cells have incorrect heights, clipping its collection view. My guess is that when table cells get reused, they don't take collection view's new intrinsicContentSize into account. I tried calling sizeToFit/layoutIfNeeded/updateConstraints in cell's prepareForReuse method, none of them works. If I replace the collection view with a multiline label, and make each cell contain different length of text, the cells all have correct heights. I wonder why label are able to correctly resize cells? how can I make collection views do the same? Thanks very much. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
UICollectionView cells sometimes drawn on top of section header
iOS 10. I'm seeing some odd behavior where occasionally collection view cells are drawn on top of their section header view instead of behind it. When I use the view inspector in Xcode then I do, in fact, see the cells in front of the section header. These are pretty generic cells that contain an image. The only thing special is that the image is loaded asynchronously and then set on the cells UIImageView in a completion block on the main thread. Has anybody else run across this behavior before? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: UICollectionView Moving
UICollectionView doesn’t know that your layout is conceptually columns, so when a section is empty, it has no concept of what space is appropriate to drop items into an empty section. You need to help it out by overriding the following method on your layout: - (NSIndexPath *)targetIndexPathForInteractivelyMovingItem:(NSIndexPath *)previousIndexPath withPosition:(CGPoint)position NS_AVAILABLE_IOS(9_0); Luke On Mar 9, 2016, at 5:58 AM, Luther Baker <lutherba...@gmail.com<mailto:lutherba...@gmail.com>> wrote: Ok - I think this is the final question. I've created a layout that is essentially a bunch of ragged bottom columns - like a Trello or Kanban board. The items in the collection view are "stories" with size around 100x100. To begin with, I prepopulate the underlying datastore and things are great, I've got 2, 3 or 4 stories in each column. Dragging around works just as expected. In my case, a column is a SECTION. A 4 column board then has 4 sections. Problem: if I move ALL the items out of a column (a column is a SECTION) ... I can't move anything back INTO the column (section). I don't think the SECTION has any HEIGHT if it has no items ... and consequently, dragging a "story" item over the area that represents a column does nothing because the CollectionView doesn't actually create anything there if I have at 0 item layoutAttributes for that section. Is there a specific way to do this? I still have a supplementary view as the column header and it always appears ... and in a UITableView, I think, if I have a empty section but have a section header, the built in move functionality will allow me to drag an item over the section header and allow me to drop into the section (but I can't remember if this is true) --- but dragging an "story" item over the supplementary view does nothing. In the worst case, do I need to keep some sort of hidden item as the first element? I take all "stories" out of a column (section), should I put at least one, invisible item in the column (section) to keep it available as a drag target? Hope that makes sense - I tend to be wordy. Thanks, -Luther On Tue, Mar 8, 2016 at 12:05 AM, Luther Baker <lutherba...@gmail.com<mailto:lutherba...@gmail.com>> wrote: Now we're cooking with GAS!!! override func applyLayoutAttributes(layoutAttributes: UICollectionViewLayoutAttributes) { print("apply layout attributes!: \(titleLabel.text)") } Thanks Man! -Luther On Mon, Mar 7, 2016 at 11:54 PM, Luke Hiesterman <luket...@apple.com<mailto:luket...@apple.com>> wrote: By teaching a cell to respond to an attribute I merely meant that it should override setLayoutAttributes: and do something in there with the relevant property. Hope that helps. Luke On Mar 7, 2016, at 9:39 PM, Luther Baker <lutherba...@gmail.com<mailto:lutherba...@gmail.com>> wrote: > teach your cell classes to respond to that property Want to think about this out loud. Wondering what would 'trigger' a lookup on the layout's layoutAttributesForItemAtIndexPath ... and where would I store the indexPath I am dragging around. If I were to be more literal - in my view controller, I handle the UIGestureRecognizerState.Began event. At this point, I can get the indexPath of the element I am about to move and if I change something on that cell at that time, it sticks for the life of the drag without reference to layoutAttributes. I also handle the UIGestureRecognizerState.Changed event and again, if I retrieve the cell at the gesture's locationInView and change things in it ... those changes stick until I let go of the drag. Stepping into the custom layout for a minute ... as you suggested, I am now implementing layoutAttributesForInteractivelyMovingItemAtIndexPath ... and that is getting invoked in response to the updateInteractiveMovementTargetPosition call I am making as the gesture location changes. Now, I know the collection view's methods are triggering the layout's callbacks - but I'm not sure what would trigger me to fetch the custom attributes you are suggesting. At a minimum, to ask the layout for the attributes at that indexPath, I'd have to actually be tracking the 'selectedIndexPath' in which case, I could just get the cell and modify it directly. I guess I'm wondering how to "teach my cells classes to respond to that property" ... Cells are reused so I'm not even sure how I'd go about setting up and tearing down a KVO type relationship for the specific cell I am dragging around. Maybe there is a WWDC video that digs into this? or it's an easy explain? Sorry for being so long-winded. I'm not sure I'm communicating my question well. Hope you can understand my underlying question and nudge me the right way but at any rate, thanks for your help so far. I'd love to use an elegant, "made for CollectionView" solution ... but I
Re: UICollectionView Moving
That was it. Thanks Luke! Really digging this control ... On Wed, Mar 9, 2016 at 10:36 AM, Luke Hiesterman <luket...@apple.com> wrote: > UICollectionView doesn’t know that your layout is conceptually columns, so > when a section is empty, it has no concept of what space is appropriate to > drop items into an empty section. You need to help it out by overriding the > following method on your layout: > > - (NSIndexPath *)targetIndexPathForInteractivelyMovingItem:(NSIndexPath > *)previousIndexPath withPosition:(CGPoint)position NS_AVAILABLE_IOS(9_0); > > Luke > > On Mar 9, 2016, at 5:58 AM, Luther Baker <lutherba...@gmail.com> wrote: > > Ok - I think this is the final question. > > I've created a layout that is essentially a bunch of ragged bottom columns > - like a Trello or Kanban board. The items in the collection view are > "stories" with size around 100x100. To begin with, I prepopulate the > underlying datastore and things are great, I've got 2, 3 or 4 stories in > each column. Dragging around works just as expected. > > In my case, a column is a SECTION. A 4 column board then has 4 sections. > > Problem: if I move ALL the items out of a column (a column is a SECTION) > ... I can't move anything back INTO the column (section). I don't think the > SECTION has any HEIGHT if it has no items ... and consequently, dragging a > "story" item over the area that represents a column does nothing because > the CollectionView doesn't actually create anything there if I have at 0 > item layoutAttributes for that section. > > Is there a specific way to do this? I still have a supplementary view as > the column header and it always appears ... and in a UITableView, I think, > if I have a empty section but have a section header, the built in move > functionality will allow me to drag an item over the section header and > allow me to drop into the section (but I can't remember if this is true) > --- but dragging an "story" item over the supplementary view does nothing. > > In the worst case, do I need to keep some sort of hidden item as the first > element? I take all "stories" out of a column (section), should I put at > least one, invisible item in the column (section) to keep it available as a > drag target? > > Hope that makes sense - I tend to be wordy. > > Thanks, > -Luther > > > > On Tue, Mar 8, 2016 at 12:05 AM, Luther Baker <lutherba...@gmail.com> > wrote: > >> Now we're cooking with GAS!!! >> >> override func applyLayoutAttributes(layoutAttributes: >> UICollectionViewLayoutAttributes) { >> print("apply layout attributes!: \(titleLabel.text)") >> } >> >> Thanks Man! >> -Luther >> >> >> >> On Mon, Mar 7, 2016 at 11:54 PM, Luke Hiesterman <luket...@apple.com> >> wrote: >> >>> By teaching a cell to respond to an attribute I merely meant that it >>> should override setLayoutAttributes: and do something in there with the >>> relevant property. Hope that helps. >>> >>> Luke >>> >>> On Mar 7, 2016, at 9:39 PM, Luther Baker <lutherba...@gmail.com> wrote: >>> >>> > teach your cell classes to respond to that property >>> >>> Want to think about this out loud. Wondering what would 'trigger' a >>> lookup on the layout's layoutAttributesForItemAtIndexPath ... and where >>> would I store the indexPath I am dragging around. >>> >>> If I were to be more literal - in my view controller, I handle the >>> UIGestureRecognizerState.Began event. At this point, I can get the >>> indexPath of the element I am about to move and if I change something on >>> that cell at that time, it sticks for the life of the drag without >>> reference to layoutAttributes. I also handle the >>> UIGestureRecognizerState.Changed event and again, if I retrieve the cell at >>> the gesture's locationInView and change things in it ... those changes >>> stick until I let go of the drag. >>> >>> Stepping into the custom layout for a minute ... as you suggested, I am >>> now implementing layoutAttributesForInteractivelyMovingItemAtIndexPath ... >>> and that is getting invoked in response to the >>> updateInteractiveMovementTargetPosition call I am making as the gesture >>> location changes. Now, I know the collection view's methods are triggering >>> the layout's callbacks - but I'm not sure what would trigger me to fetch >>> the custom attributes you are suggesting. At a minimum, to ask the layout >>> for the attributes at that indexPath, I'd have to
Re: UICollectionView Moving
change it (or does it not require >> the delegates or datasources ... ?) >> >> Thanks, >> -Luther >> >> >> >> On Mon, Mar 7, 2016 at 2:45 PM, Luke Hiesterman <luket...@apple.com> >> wrote: >> >>> You can create your own subclass of UICollectionViewLayoutAttributes and >>> add something like an “isMoving” property to that. Then teach your cell >>> classes to respond to that property by changing the background color. >>> >>> Luke >>> >>> On Mar 7, 2016, at 11:44 AM, Luther Baker <lutherba...@gmail.com> wrote: >>> >>> Thanks Luke! That was it - I can drag and drop successfully now. >>> >>> One more question, how do I modify a property of the item I'm dragging >>> around if the property is NOT currently in UICollectionViewLayoutAttributes >>> ... I don't see a call to the datasource or delegate when I select the cell >>> for moving ... so I'm not sure how to change the background color to "red" >>> for instance. >>> >>> Would I have to add my own view to the superview and manually move it >>> around in the dragging callbacks? >>> >>> Thanks! >>> -Luther >>> >>> >>> On Mon, Mar 7, 2016 at 11:59 AM, Luke Hiesterman <luket...@apple.com> >>> wrote: >>> >>>> I’d check your return value for this method in your layout: >>>> >>>> - (UICollectionViewLayoutAttributes >>>> *)layoutAttributesForInteractivelyMovingItemAtIndexPath:(NSIndexPath >>>> *)indexPath withTargetPosition:(CGPoint)position NS_AVAILABLE_IOS(9_0); >>>> >>>> Luke >>>> >>>> On Mar 7, 2016, at 9:55 AM, Luther Baker <lutherba...@gmail.com> wrote: >>>> >>>> I followed the directions here, >>>> >>>> http://nshint.io/blog/2015/07/16/uicollectionviews-now-have-easy-reordering/ >>>> - to add iOS9 style dragging to my UICollectionView - and it sort of >>>> works. >>>> >>>> As described in the article, I added a long press gesture recognizer and >>>> wired it in to make calls on the collection view -- but now, if I long >>>> press, the element under my finger disappears. As I drag the transparent >>>> image around, the other elements shift - but I can never see the >>>> element I >>>> am dragging around. When I let go, there is simply a hole left where I >>>> "dropped" the element. >>>> >>>> I do, very much, have a custom layout and I'm not sure that if, for >>>> drag, I >>>> need to do anything special. Do I need to calculate the frame of the >>>> item I >>>> am dragging around? I'm not sure what to try next except to roll my own >>>> dragging. Any thoughts or things to try? >>>> >>>> Thanks in advance. >>>> ___ >>>> >>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) >>>> >>>> Please do not post admin requests or moderator comments to the list. >>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com >>>> >>>> Help/Unsubscribe/Update your Subscription: >>>> https://lists.apple.com/mailman/options/cocoa-dev/luketheh%40apple.com >>>> >>>> This email sent to luket...@apple.com >>>> >>>> >>>> >>> >>> >> > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: UICollectionView Moving
Now we're cooking with GAS!!! override func applyLayoutAttributes(layoutAttributes: UICollectionViewLayoutAttributes) { print("apply layout attributes!: \(titleLabel.text)") } Thanks Man! -Luther On Mon, Mar 7, 2016 at 11:54 PM, Luke Hiesterman <luket...@apple.com> wrote: > By teaching a cell to respond to an attribute I merely meant that it > should override setLayoutAttributes: and do something in there with the > relevant property. Hope that helps. > > Luke > > On Mar 7, 2016, at 9:39 PM, Luther Baker <lutherba...@gmail.com> wrote: > > > teach your cell classes to respond to that property > > Want to think about this out loud. Wondering what would 'trigger' a lookup > on the layout's layoutAttributesForItemAtIndexPath ... and where would I > store the indexPath I am dragging around. > > If I were to be more literal - in my view controller, I handle the > UIGestureRecognizerState.Began event. At this point, I can get the > indexPath of the element I am about to move and if I change something on > that cell at that time, it sticks for the life of the drag without > reference to layoutAttributes. I also handle the > UIGestureRecognizerState.Changed event and again, if I retrieve the cell at > the gesture's locationInView and change things in it ... those changes > stick until I let go of the drag. > > Stepping into the custom layout for a minute ... as you suggested, I am > now implementing layoutAttributesForInteractivelyMovingItemAtIndexPath ... > and that is getting invoked in response to the > updateInteractiveMovementTargetPosition call I am making as the gesture > location changes. Now, I know the collection view's methods are triggering > the layout's callbacks - but I'm not sure what would trigger me to fetch > the custom attributes you are suggesting. At a minimum, to ask the layout > for the attributes at that indexPath, I'd have to actually be tracking the > 'selectedIndexPath' in which case, I could just get the cell and modify it > directly. > > I guess I'm wondering how to "teach my cells classes to respond to that > property" ... Cells are reused so I'm not even sure how I'd go about > setting up and tearing down a KVO type relationship for the specific cell I > am dragging around. Maybe there is a WWDC video that digs into this? or > it's an easy explain? > > Sorry for being so long-winded. I'm not sure I'm communicating my question > well. Hope you can understand my underlying question and nudge me the right > way but at any rate, thanks for your help so far. I'd love to use an > elegant, "made for CollectionView" solution ... but I don't think I'm > looking at it correctly yet. Just in general I guess, how can a change to > the layoutAttributes cause my CollectionViewDelegate and DataSources to > fetch the cell I'm dragging around and change it (or does it not require > the delegates or datasources ... ?) > > Thanks, > -Luther > > > > On Mon, Mar 7, 2016 at 2:45 PM, Luke Hiesterman <luket...@apple.com> > wrote: > >> You can create your own subclass of UICollectionViewLayoutAttributes and >> add something like an “isMoving” property to that. Then teach your cell >> classes to respond to that property by changing the background color. >> >> Luke >> >> On Mar 7, 2016, at 11:44 AM, Luther Baker <lutherba...@gmail.com> wrote: >> >> Thanks Luke! That was it - I can drag and drop successfully now. >> >> One more question, how do I modify a property of the item I'm dragging >> around if the property is NOT currently in UICollectionViewLayoutAttributes >> ... I don't see a call to the datasource or delegate when I select the cell >> for moving ... so I'm not sure how to change the background color to "red" >> for instance. >> >> Would I have to add my own view to the superview and manually move it >> around in the dragging callbacks? >> >> Thanks! >> -Luther >> >> >> On Mon, Mar 7, 2016 at 11:59 AM, Luke Hiesterman <luket...@apple.com> >> wrote: >> >>> I’d check your return value for this method in your layout: >>> >>> - (UICollectionViewLayoutAttributes >>> *)layoutAttributesForInteractivelyMovingItemAtIndexPath:(NSIndexPath >>> *)indexPath withTargetPosition:(CGPoint)position NS_AVAILABLE_IOS(9_0); >>> >>> Luke >>> >>> On Mar 7, 2016, at 9:55 AM, Luther Baker <lutherba...@gmail.com> wrote: >>> >>> I followed the directions here, >>> >>> http://nshint.io/blog/2015/07/16/uicollectionviews-now-have-easy-reordering/ >>> - to add iOS9 style dragging
Re: UICollectionView Moving
By teaching a cell to respond to an attribute I merely meant that it should override setLayoutAttributes: and do something in there with the relevant property. Hope that helps. Luke On Mar 7, 2016, at 9:39 PM, Luther Baker <lutherba...@gmail.com<mailto:lutherba...@gmail.com>> wrote: > teach your cell classes to respond to that property Want to think about this out loud. Wondering what would 'trigger' a lookup on the layout's layoutAttributesForItemAtIndexPath ... and where would I store the indexPath I am dragging around. If I were to be more literal - in my view controller, I handle the UIGestureRecognizerState.Began event. At this point, I can get the indexPath of the element I am about to move and if I change something on that cell at that time, it sticks for the life of the drag without reference to layoutAttributes. I also handle the UIGestureRecognizerState.Changed event and again, if I retrieve the cell at the gesture's locationInView and change things in it ... those changes stick until I let go of the drag. Stepping into the custom layout for a minute ... as you suggested, I am now implementing layoutAttributesForInteractivelyMovingItemAtIndexPath ... and that is getting invoked in response to the updateInteractiveMovementTargetPosition call I am making as the gesture location changes. Now, I know the collection view's methods are triggering the layout's callbacks - but I'm not sure what would trigger me to fetch the custom attributes you are suggesting. At a minimum, to ask the layout for the attributes at that indexPath, I'd have to actually be tracking the 'selectedIndexPath' in which case, I could just get the cell and modify it directly. I guess I'm wondering how to "teach my cells classes to respond to that property" ... Cells are reused so I'm not even sure how I'd go about setting up and tearing down a KVO type relationship for the specific cell I am dragging around. Maybe there is a WWDC video that digs into this? or it's an easy explain? Sorry for being so long-winded. I'm not sure I'm communicating my question well. Hope you can understand my underlying question and nudge me the right way but at any rate, thanks for your help so far. I'd love to use an elegant, "made for CollectionView" solution ... but I don't think I'm looking at it correctly yet. Just in general I guess, how can a change to the layoutAttributes cause my CollectionViewDelegate and DataSources to fetch the cell I'm dragging around and change it (or does it not require the delegates or datasources ... ?) Thanks, -Luther On Mon, Mar 7, 2016 at 2:45 PM, Luke Hiesterman <luket...@apple.com<mailto:luket...@apple.com>> wrote: You can create your own subclass of UICollectionViewLayoutAttributes and add something like an “isMoving” property to that. Then teach your cell classes to respond to that property by changing the background color. Luke On Mar 7, 2016, at 11:44 AM, Luther Baker <lutherba...@gmail.com<mailto:lutherba...@gmail.com>> wrote: Thanks Luke! That was it - I can drag and drop successfully now. One more question, how do I modify a property of the item I'm dragging around if the property is NOT currently in UICollectionViewLayoutAttributes ... I don't see a call to the datasource or delegate when I select the cell for moving ... so I'm not sure how to change the background color to "red" for instance. Would I have to add my own view to the superview and manually move it around in the dragging callbacks? Thanks! -Luther On Mon, Mar 7, 2016 at 11:59 AM, Luke Hiesterman <luket...@apple.com<mailto:luket...@apple.com>> wrote: I’d check your return value for this method in your layout: - (UICollectionViewLayoutAttributes *)layoutAttributesForInteractivelyMovingItemAtIndexPath:(NSIndexPath *)indexPath withTargetPosition:(CGPoint)position NS_AVAILABLE_IOS(9_0); Luke On Mar 7, 2016, at 9:55 AM, Luther Baker <lutherba...@gmail.com<mailto:lutherba...@gmail.com>> wrote: I followed the directions here, http://nshint.io/blog/2015/07/16/uicollectionviews-now-have-easy-reordering/ - to add iOS9 style dragging to my UICollectionView - and it sort of works. As described in the article, I added a long press gesture recognizer and wired it in to make calls on the collection view -- but now, if I long press, the element under my finger disappears. As I drag the transparent image around, the other elements shift - but I can never see the element I am dragging around. When I let go, there is simply a hole left where I "dropped" the element. I do, very much, have a custom layout and I'm not sure that if, for drag, I need to do anything special. Do I need to calculate the frame of the item I am dragging around? I'm not sure what to try next except to roll my own dragging. Any thoughts or things to try? Thanks in advance. __
Re: UICollectionView Moving
> teach your cell classes to respond to that property Want to think about this out loud. Wondering what would 'trigger' a lookup on the layout's layoutAttributesForItemAtIndexPath ... and where would I store the indexPath I am dragging around. If I were to be more literal - in my view controller, I handle the UIGestureRecognizerState.Began event. At this point, I can get the indexPath of the element I am about to move and if I change something on that cell at that time, it sticks for the life of the drag without reference to layoutAttributes. I also handle the UIGestureRecognizerState.Changed event and again, if I retrieve the cell at the gesture's locationInView and change things in it ... those changes stick until I let go of the drag. Stepping into the custom layout for a minute ... as you suggested, I am now implementing layoutAttributesForInteractivelyMovingItemAtIndexPath ... and that is getting invoked in response to the updateInteractiveMovementTargetPosition call I am making as the gesture location changes. Now, I know the collection view's methods are triggering the layout's callbacks - but I'm not sure what would trigger me to fetch the custom attributes you are suggesting. At a minimum, to ask the layout for the attributes at that indexPath, I'd have to actually be tracking the 'selectedIndexPath' in which case, I could just get the cell and modify it directly. I guess I'm wondering how to "teach my cells classes to respond to that property" ... Cells are reused so I'm not even sure how I'd go about setting up and tearing down a KVO type relationship for the specific cell I am dragging around. Maybe there is a WWDC video that digs into this? or it's an easy explain? Sorry for being so long-winded. I'm not sure I'm communicating my question well. Hope you can understand my underlying question and nudge me the right way but at any rate, thanks for your help so far. I'd love to use an elegant, "made for CollectionView" solution ... but I don't think I'm looking at it correctly yet. Just in general I guess, how can a change to the layoutAttributes cause my CollectionViewDelegate and DataSources to fetch the cell I'm dragging around and change it (or does it not require the delegates or datasources ... ?) Thanks, -Luther On Mon, Mar 7, 2016 at 2:45 PM, Luke Hiesterman <luket...@apple.com> wrote: > You can create your own subclass of UICollectionViewLayoutAttributes and > add something like an “isMoving” property to that. Then teach your cell > classes to respond to that property by changing the background color. > > Luke > > On Mar 7, 2016, at 11:44 AM, Luther Baker <lutherba...@gmail.com> wrote: > > Thanks Luke! That was it - I can drag and drop successfully now. > > One more question, how do I modify a property of the item I'm dragging > around if the property is NOT currently in UICollectionViewLayoutAttributes > ... I don't see a call to the datasource or delegate when I select the cell > for moving ... so I'm not sure how to change the background color to "red" > for instance. > > Would I have to add my own view to the superview and manually move it > around in the dragging callbacks? > > Thanks! > -Luther > > > On Mon, Mar 7, 2016 at 11:59 AM, Luke Hiesterman <luket...@apple.com> > wrote: > >> I’d check your return value for this method in your layout: >> >> - (UICollectionViewLayoutAttributes >> *)layoutAttributesForInteractivelyMovingItemAtIndexPath:(NSIndexPath >> *)indexPath withTargetPosition:(CGPoint)position NS_AVAILABLE_IOS(9_0); >> >> Luke >> >> On Mar 7, 2016, at 9:55 AM, Luther Baker <lutherba...@gmail.com> wrote: >> >> I followed the directions here, >> >> http://nshint.io/blog/2015/07/16/uicollectionviews-now-have-easy-reordering/ >> - to add iOS9 style dragging to my UICollectionView - and it sort of >> works. >> >> As described in the article, I added a long press gesture recognizer and >> wired it in to make calls on the collection view -- but now, if I long >> press, the element under my finger disappears. As I drag the transparent >> image around, the other elements shift - but I can never see the element I >> am dragging around. When I let go, there is simply a hole left where I >> "dropped" the element. >> >> I do, very much, have a custom layout and I'm not sure that if, for drag, >> I >> need to do anything special. Do I need to calculate the frame of the item >> I >> am dragging around? I'm not sure what to try next except to roll my own >> dragging. Any thoughts or things to try? >> >> Thanks in advance. >> ___ >> >> Cocoa-de
Re: UICollectionView Moving
You can create your own subclass of UICollectionViewLayoutAttributes and add something like an “isMoving” property to that. Then teach your cell classes to respond to that property by changing the background color. Luke On Mar 7, 2016, at 11:44 AM, Luther Baker <lutherba...@gmail.com<mailto:lutherba...@gmail.com>> wrote: Thanks Luke! That was it - I can drag and drop successfully now. One more question, how do I modify a property of the item I'm dragging around if the property is NOT currently in UICollectionViewLayoutAttributes ... I don't see a call to the datasource or delegate when I select the cell for moving ... so I'm not sure how to change the background color to "red" for instance. Would I have to add my own view to the superview and manually move it around in the dragging callbacks? Thanks! -Luther On Mon, Mar 7, 2016 at 11:59 AM, Luke Hiesterman <luket...@apple.com<mailto:luket...@apple.com>> wrote: I’d check your return value for this method in your layout: - (UICollectionViewLayoutAttributes *)layoutAttributesForInteractivelyMovingItemAtIndexPath:(NSIndexPath *)indexPath withTargetPosition:(CGPoint)position NS_AVAILABLE_IOS(9_0); Luke On Mar 7, 2016, at 9:55 AM, Luther Baker <lutherba...@gmail.com<mailto:lutherba...@gmail.com>> wrote: I followed the directions here, http://nshint.io/blog/2015/07/16/uicollectionviews-now-have-easy-reordering/ - to add iOS9 style dragging to my UICollectionView - and it sort of works. As described in the article, I added a long press gesture recognizer and wired it in to make calls on the collection view -- but now, if I long press, the element under my finger disappears. As I drag the transparent image around, the other elements shift - but I can never see the element I am dragging around. When I let go, there is simply a hole left where I "dropped" the element. I do, very much, have a custom layout and I'm not sure that if, for drag, I need to do anything special. Do I need to calculate the frame of the item I am dragging around? I'm not sure what to try next except to roll my own dragging. Any thoughts or things to try? Thanks in advance. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com<mailto:Cocoa-dev@lists.apple.com>) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com<http://lists.apple.com/> Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/luketheh%40apple.com This email sent to luket...@apple.com<mailto:luket...@apple.com> ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: UICollectionView Moving
Thanks Luke! That was it - I can drag and drop successfully now. One more question, how do I modify a property of the item I'm dragging around if the property is NOT currently in UICollectionViewLayoutAttributes ... I don't see a call to the datasource or delegate when I select the cell for moving ... so I'm not sure how to change the background color to "red" for instance. Would I have to add my own view to the superview and manually move it around in the dragging callbacks? Thanks! -Luther On Mon, Mar 7, 2016 at 11:59 AM, Luke Hiesterman <luket...@apple.com> wrote: > I’d check your return value for this method in your layout: > > - (UICollectionViewLayoutAttributes > *)layoutAttributesForInteractivelyMovingItemAtIndexPath:(NSIndexPath > *)indexPath withTargetPosition:(CGPoint)position NS_AVAILABLE_IOS(9_0); > > Luke > > On Mar 7, 2016, at 9:55 AM, Luther Baker <lutherba...@gmail.com> wrote: > > I followed the directions here, > > http://nshint.io/blog/2015/07/16/uicollectionviews-now-have-easy-reordering/ > - to add iOS9 style dragging to my UICollectionView - and it sort of works. > > As described in the article, I added a long press gesture recognizer and > wired it in to make calls on the collection view -- but now, if I long > press, the element under my finger disappears. As I drag the transparent > image around, the other elements shift - but I can never see the element I > am dragging around. When I let go, there is simply a hole left where I > "dropped" the element. > > I do, very much, have a custom layout and I'm not sure that if, for drag, I > need to do anything special. Do I need to calculate the frame of the item I > am dragging around? I'm not sure what to try next except to roll my own > dragging. Any thoughts or things to try? > > Thanks in advance. > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/luketheh%40apple.com > > This email sent to luket...@apple.com > > > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: UICollectionView Moving
I’d check your return value for this method in your layout: - (UICollectionViewLayoutAttributes *)layoutAttributesForInteractivelyMovingItemAtIndexPath:(NSIndexPath *)indexPath withTargetPosition:(CGPoint)position NS_AVAILABLE_IOS(9_0); Luke On Mar 7, 2016, at 9:55 AM, Luther Baker <lutherba...@gmail.com<mailto:lutherba...@gmail.com>> wrote: I followed the directions here, http://nshint.io/blog/2015/07/16/uicollectionviews-now-have-easy-reordering/ - to add iOS9 style dragging to my UICollectionView - and it sort of works. As described in the article, I added a long press gesture recognizer and wired it in to make calls on the collection view -- but now, if I long press, the element under my finger disappears. As I drag the transparent image around, the other elements shift - but I can never see the element I am dragging around. When I let go, there is simply a hole left where I "dropped" the element. I do, very much, have a custom layout and I'm not sure that if, for drag, I need to do anything special. Do I need to calculate the frame of the item I am dragging around? I'm not sure what to try next except to roll my own dragging. Any thoughts or things to try? Thanks in advance. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/luketheh%40apple.com This email sent to luket...@apple.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
UICollectionView Moving
I followed the directions here, http://nshint.io/blog/2015/07/16/uicollectionviews-now-have-easy-reordering/ - to add iOS9 style dragging to my UICollectionView - and it sort of works. As described in the article, I added a long press gesture recognizer and wired it in to make calls on the collection view -- but now, if I long press, the element under my finger disappears. As I drag the transparent image around, the other elements shift - but I can never see the element I am dragging around. When I let go, there is simply a hole left where I "dropped" the element. I do, very much, have a custom layout and I'm not sure that if, for drag, I need to do anything special. Do I need to calculate the frame of the item I am dragging around? I'm not sure what to try next except to roll my own dragging. Any thoughts or things to try? Thanks in advance. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Setting the contentOffset of a UICollectionView during update
I have a collection view, with a custom layout, whose layout is changing when one taps on a cell: the cell becomes bigger. The layout is not a sublass of UIViewCollectionViewFlowLayout but directly of UICollectionViewLayout. I update the layout with [self.collectionView performBatchUpdates: ^{[self.tableView reloadItemsAtIndexPaths:indexPathsToUpdate];} completion:nil]; (I do implement the methods finalLayoutAttributesForDisappearingItemAtIndexPath: etc.) The problem is that after the update, the contentOffset is not good anymore: I want the specific cell to be centered, but after the update it is not centered. I tried to change the offset in the method finalizeCollectionViewUpdates: of my custom layout.I also tried to implement the method - targetContentOffsetForProposedContentOffset: But the problem is always the same. During the animation, the cells that were not visible and become visible don't appear. They stay as "blank space" and only at the end of the animation they appear, all of a sudden. So my question is, how to change the contentOffset of a UICollectionView during layout updates? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: UICollectionView not obeying zIndex of UICollectionViewLayoutAttributes
Thanks for the reply. I made a standalone project in order to strip out all my extraneous code. In the process I think I found my own solution. override func initialLayoutAttributesForAppearingItemAtIndexPath(itemIndexPath: NSIndexPath) - UICollectionViewLayoutAttributes? override func finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath: NSIndexPath) - UICollectionViewLayoutAttributes? were not also applying the new zIndex so I think this was what was causing it. Just thought I should post back the solution in case this comes up in a search for anyone else. Thanks again, Ted On 6 Aug 2015, at 16:42, Luke Hiesterman luket...@apple.com wrote: Can you post your implementations -layoutAttributesForElementsInRect: as well as -layoutAttributesForItemAtIndexPath:? Luke On Aug 6, 2015, at 8:09 AM, Ted Bradley earlte...@googlemail.com wrote: The effect I'm trying to achieve is a kind of sticky header cell. It's important to me that the sticky cell floats over the top of the others. Something a bit like this: ┌──┐ │ │ │ Cell 0 │ │ ├┐ └┬─┘│ │ Cell 4 │ │ │ └──┘ ┌──┐ │ │ │ Cell 5 │ │ │ └──┘ ┌──┐ │ │ │ Cell 6 │ │ │ └──┘ Cell 4, 5 and 6 would normally viewable and I'm constructing the attributes for cell 0 in my UICollectionViewFlowLayout subclass during layoutAttributesForElementsInRect:. All I do is call the super implementation, determine which cell I need to add in and then construct the UICollectionViewLayoutAttributes(forCellWithIndexPath:). I then set the zIndex for it to 1 (default is `0`). The problem I'm getting is that the UICollectionView seems to always ignore the `zIndex` ┌──┐ │ │ │ Cell 0 │ │┌─┴┐ └┤ │ │ Cell 4 │ │ │ └──┘ ┌──┐ │ │ │ Cell 5 │ │ │ └──┘ ┌──┐ │ │ │ Cell 6 │ │ │ └──┘ Now I believe it's possible to visually sort this out using a 3d transform, but that doesn't work for me as I don't want any taps going to the cell which is over the top. So in this example I don't want Cell 4 receiving taps intended for Cell 0. Does anyone have any ideas? This is on iOS 8.4. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/luketheh%40apple.com This email sent to luket...@apple.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
UICollectionView not obeying zIndex of UICollectionViewLayoutAttributes
The effect I'm trying to achieve is a kind of sticky header cell. It's important to me that the sticky cell floats over the top of the others. Something a bit like this: ┌──┐ │ │ │ Cell 0 │ │ ├┐ └┬─┘│ │ Cell 4 │ │ │ └──┘ ┌──┐ │ │ │ Cell 5 │ │ │ └──┘ ┌──┐ │ │ │ Cell 6 │ │ │ └──┘ Cell 4, 5 and 6 would normally viewable and I'm constructing the attributes for cell 0 in my UICollectionViewFlowLayout subclass during layoutAttributesForElementsInRect:. All I do is call the super implementation, determine which cell I need to add in and then construct the UICollectionViewLayoutAttributes(forCellWithIndexPath:). I then set the zIndex for it to 1 (default is `0`). The problem I'm getting is that the UICollectionView seems to always ignore the `zIndex` ┌──┐ │ │ │ Cell 0 │ │┌─┴┐ └┤ │ │ Cell 4 │ │ │ └──┘ ┌──┐ │ │ │ Cell 5 │ │ │ └──┘ ┌──┐ │ │ │ Cell 6 │ │ │ └──┘ Now I believe it's possible to visually sort this out using a 3d transform, but that doesn't work for me as I don't want any taps going to the cell which is over the top. So in this example I don't want Cell 4 receiving taps intended for Cell 0. Does anyone have any ideas? This is on iOS 8.4. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: UICollectionView not obeying zIndex of UICollectionViewLayoutAttributes
Can you post your implementations -layoutAttributesForElementsInRect: as well as -layoutAttributesForItemAtIndexPath:? Luke On Aug 6, 2015, at 8:09 AM, Ted Bradley earlte...@googlemail.com wrote: The effect I'm trying to achieve is a kind of sticky header cell. It's important to me that the sticky cell floats over the top of the others. Something a bit like this: ┌──┐ │ │ │ Cell 0 │ │ ├┐ └┬─┘│ │ Cell 4 │ │ │ └──┘ ┌──┐ │ │ │ Cell 5 │ │ │ └──┘ ┌──┐ │ │ │ Cell 6 │ │ │ └──┘ Cell 4, 5 and 6 would normally viewable and I'm constructing the attributes for cell 0 in my UICollectionViewFlowLayout subclass during layoutAttributesForElementsInRect:. All I do is call the super implementation, determine which cell I need to add in and then construct the UICollectionViewLayoutAttributes(forCellWithIndexPath:). I then set the zIndex for it to 1 (default is `0`). The problem I'm getting is that the UICollectionView seems to always ignore the `zIndex` ┌──┐ │ │ │ Cell 0 │ │┌─┴┐ └┤ │ │ Cell 4 │ │ │ └──┘ ┌──┐ │ │ │ Cell 5 │ │ │ └──┘ ┌──┐ │ │ │ Cell 6 │ │ │ └──┘ Now I believe it's possible to visually sort this out using a 3d transform, but that doesn't work for me as I don't want any taps going to the cell which is over the top. So in this example I don't want Cell 4 receiving taps intended for Cell 0. Does anyone have any ideas? This is on iOS 8.4. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/luketheh%40apple.com This email sent to luket...@apple.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Serious bug for UICollectionView
Dear cocoa-dev, I am facing the following bug with `UICollectionView` in the **horizontal scrolling mode** (`iOS 8`, `iOS 7`, the only ones I have tested). I would like to have your views on this bug and on how I could elegantly fix it (and possibly fix it so that when Apple fixes it, my fix won't bring unattended effects). The message is also for reporting the bug to the community. I have already sent a report to Apple. I set up the collection view manually, and choose a flow layout with an horizontal scrolling. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init] ; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal ; layout.minimumInteritemSpacing = 5 ; layout.minimumLineSpacing = 100 ; The bug happens when the cells in the UICollectionView does not have the same sizes. -- when all the cells have the same size, • minimumInteritemSpacing is for the vertical space between cells • minimumLineSpacing is for the horizontal space -- BUT as soon as one of the cells have a different size, the roles are interchanged: • minimumInteritemSpacing is for the horizontal space between cells • minimumLineSpacing is for the vertical space. ## Link to a minimal non-working example https://github.com/colasjojo/TEST_COLLECTION_VIEW_BUG ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Set UICollectionView UIScrollViewDelegate delegate
Hi, I have a parent view controller that has two UICollectionViewController subclasses as children in its view controller hierarchy. I'd like to set the parentViewController as the Subclass1CollectionViewController and Subclass2CollectionViewControllers' .colllectionView UIScrollView delegate. However when I set the delegate, the compiler assumes I'm trying to assign it as the UICollectionViewDelegate. UICollectionView is a subclass of UIScrollView.. how do refer to its scrollview delegate pointer? Xcode 6.0.1 iOS8. self.bodyCollectionViewController.collectionView.backgroundColor = UIColor.clearColor; self.bodyCollectionViewController.collectionView.showsHorizontalScrollIndicator = NO; self.bodyCollectionViewController.collectionView.showsVerticalScrollIndicator = NO; self.bodyCollectionViewController.collectionView.delegate = self; // warning -- Assigning to 'idUICollectionViewDelegate' from incompatible type 'SCRPreviewViewController *const __strong' @interface SCRPreviewViewController : UIViewController UIScrollViewDelegate ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Set UICollectionView UIScrollViewDelegate delegate
On Oct 18, 2014, at 2:22 PM, Mazzaroth M. taomaili...@gmail.com wrote: Hi, I have a parent view controller that has two UICollectionViewController subclasses as children in its view controller hierarchy. I'd like to set the parentViewController as the Subclass1CollectionViewController and Subclass2CollectionViewControllers' .colllectionView UIScrollView delegate. However when I set the delegate, the compiler assumes I'm trying to assign it as the UICollectionViewDelegate. UICollectionView is a subclass of UIScrollView.. how do refer to its scrollview delegate pointer? There is only one delegate property. UICollectionView redeclares the property it inherits from UIScrollView and retypes it as UICollectionViewDelegate, which extends UIScrollViewDelegate. Any object you assign as the collection view’s delegate *must* conform to UICollectionViewDelegate. The good news is that every member of UICollectionViewDelegate is optional, so this is a trivial change. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: UICollectionView parallax-like horizontal scrolling
There are multiple ways to skin this cat. One is to use two collection views and just modify the content offset of one of them in response to the scrolling of the other. The behavior can also be built into a layout if you want to use a single scroll view. You don’t need different types of cells - you just need your layout to make a choice about how it wants each index path to behave. As an example, I might create a two column layout where all the even numbered indexes are on the left and all the odd numbered indexes are on the right. Or maybe it would be something different than that - maybe the first section would go on the left and the second section would go on the right. Could be anything. Then if I decided I want the right column to scroll faster than normal to create the parallax effect, I would return YES from -shouldInvalidateLayoutForBoundsChange: and then modify the positions of the layout attributes for all the items in the right hand column based on some math relative to the content offset. This would accomplish updating the frames of the right hand column cells every frame that a scroll occurs and achieve the parallax effect. Luke On Oct 15, 2014, at 10:01 PM, Mazzaroth M. taomaili...@gmail.com wrote: In the running apps view(double-tap Home button) there are two rows each which contain two different types of cells. How would one implement this using UICollectionView? I more or less want to do this where the lower row cells are slightly narrower than the upper row such that when you swipe to scroll, the items in both rows are centred on the screen at the same time but because the items in row 1 are slightly narrower, they will scroll slightly faster than the items in row 0 creating a parallax-like effect. An extreme example of this would be https://github.com/allaboutapps/A3ParallaxScrollView in the tree example, however this is done with a custom UIScrollView subclass. And so, I know that this is possible but not sure if I can do it with UICollectionView and may need to use UIScrollView instead(however would prefer to figure it out with UICollectionView). In my attempts for UICollectionView, I was thinking that I'd need to use one type of cell for row 0 and another type of cell for row 1, but it's not clear to me how to specify a different layout for each of the rows, which appears to be what I need to do. Any thoughts on this? maz ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/luketheh%40apple.com This email sent to luket...@apple.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: UICollectionView parallax-like horizontal scrolling
Thanks, will investigate your suggestions. On Thu, Oct 16, 2014 at 10:54 AM, Luke Hiesterman luket...@apple.com wrote: There are multiple ways to skin this cat. One is to use two collection views and just modify the content offset of one of them in response to the scrolling of the other. The behavior can also be built into a layout if you want to use a single scroll view. You don’t need different types of cells - you just need your layout to make a choice about how it wants each index path to behave. As an example, I might create a two column layout where all the even numbered indexes are on the left and all the odd numbered indexes are on the right. Or maybe it would be something different than that - maybe the first section would go on the left and the second section would go on the right. Could be anything. Then if I decided I want the right column to scroll faster than normal to create the parallax effect, I would return YES from -shouldInvalidateLayoutForBoundsChange: and then modify the positions of the layout attributes for all the items in the right hand column based on some math relative to the content offset. This would accomplish updating the frames of the right hand column cells every frame that a scroll occurs and achieve the parallax effect. Luke On Oct 15, 2014, at 10:01 PM, Mazzaroth M. taomaili...@gmail.com wrote: In the running apps view(double-tap Home button) there are two rows each which contain two different types of cells. How would one implement this using UICollectionView? I more or less want to do this where the lower row cells are slightly narrower than the upper row such that when you swipe to scroll, the items in both rows are centred on the screen at the same time but because the items in row 1 are slightly narrower, they will scroll slightly faster than the items in row 0 creating a parallax-like effect. An extreme example of this would be https://github.com/allaboutapps/A3ParallaxScrollView in the tree example, however this is done with a custom UIScrollView subclass. And so, I know that this is possible but not sure if I can do it with UICollectionView and may need to use UIScrollView instead(however would prefer to figure it out with UICollectionView). In my attempts for UICollectionView, I was thinking that I'd need to use one type of cell for row 0 and another type of cell for row 1, but it's not clear to me how to specify a different layout for each of the rows, which appears to be what I need to do. Any thoughts on this? maz ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/luketheh%40apple.com This email sent to luket...@apple.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
UICollectionView parallax-like horizontal scrolling
In the running apps view(double-tap Home button) there are two rows each which contain two different types of cells. How would one implement this using UICollectionView? I more or less want to do this where the lower row cells are slightly narrower than the upper row such that when you swipe to scroll, the items in both rows are centred on the screen at the same time but because the items in row 1 are slightly narrower, they will scroll slightly faster than the items in row 0 creating a parallax-like effect. An extreme example of this would be https://github.com/allaboutapps/A3ParallaxScrollView in the tree example, however this is done with a custom UIScrollView subclass. And so, I know that this is possible but not sure if I can do it with UICollectionView and may need to use UIScrollView instead(however would prefer to figure it out with UICollectionView). In my attempts for UICollectionView, I was thinking that I'd need to use one type of cell for row 0 and another type of cell for row 1, but it's not clear to me how to specify a different layout for each of the rows, which appears to be what I need to do. Any thoughts on this? maz ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
How to get variably sized header in a UICollectionView supporting both orientations
Becoming increasingly adept at autolayout but currently stumped. What I am trying to do is design a UICollectionView header that using constraints is suitable for portrait and landscape. I have a bunch of views in it, each grouped into a container view. What I'd like to do is when the view rotates, move the container views around. Currently this seems impossible because the size of the header (and footer) must be specified to the Flow Layout before the view is even created, and it appears to be fixed from them on. As it stands now, what I'm doing is creating the header in code, and using knowledge of what orientation the view will be shown in, and varying the constraints on the container views. By reloading the collection view on every rotation, I can get a new (and properly) sized header. This seems like driving a nail with a sledgehammer, but nothing else comes to mind. Very open to suggestions on better methods. David ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to get variably sized header in a UICollectionView supporting both orientations
On Oct 4, 2013, at 11:35 AM, David Hoerl dho...@mac.com wrote: Becoming increasingly adept at autolayout but currently stumped. What I am trying to do is design a UICollectionView header that using constraints is suitable for portrait and landscape. I have a bunch of views in it, each grouped into a container view. What I'd like to do is when the view rotates, move the container views around. Currently this seems impossible because the size of the header (and footer) must be specified to the Flow Layout before the view is even created, and it appears to be fixed from them on. Do you mean the header/footerReferenceSize properties? If so I would think this would just work, since the flow layout will automatically size the width or height (depending on the scrolling direction) to fill the width or height of the collection view, allowing your container to just specify its sizes relative to the parent view size without needing to know the orientation. But maybe I just don’t understand exactly what you are running up against? As it stands now, what I'm doing is creating the header in code, and using knowledge of what orientation the view will be shown in, and varying the constraints on the container views. By reloading the collection view on every rotation, I can get a new (and properly) sized header. This seems like driving a nail with a sledgehammer, but nothing else comes to mind. Very open to suggestions on better methods. David ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com This email sent to david.dun...@apple.com -- David Duncan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to get variably sized header in a UICollectionView supporting both orientations
I have a bunch of views in it, each grouped into a container view. What I'd like to do is when the view rotates, move the container views around. Currently this seems impossible because the size of the header (and footer) must be specified to the Flow Layout before the view is even created, and it appears to be fixed from them on. Do you mean the header/footerReferenceSize properties? No If so I would think this would just work, since the flow layout will automatically size the width or height (depending on the scrolling direction) to fill the width or height of the collection view, allowing your container to just specify its sizes relative to the parent view size without needing to know the orientation. But maybe I just don’t understand exactly what you are running up against? I have two sections, so have to use the Flow Delegate callback to supply the sizes: - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section The Flow Layout object asks for the sizes first, then the header (or footer if used). I tried returning one size in the above delegate method, then a larger header, but the collection view does not appear to look at the view's size, instead honoring the delegate returned value. Hmmm - it looks like I overlooked sending the layout object invalidateLayout. I just did that in the willAnimate... rotation view controller method, and I observe the layout object asked again the the header height. But its really odd - and I'm thinking about a bug report on this - that the delegate has to provide the size before the view is even created. So what I do now is create a header view in view did load, ask it for its size using systemLayoutSizeFittingSize, then release it, just to get the size (its using the new dynamic text so this is the only way to get its size). Later, Flow Layout asks for the size, then in another delegate call I dequeue a header view whose size I now know. I tried to cache the first view but that failed. -- David Duncan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to get variably sized header in a UICollectionView supporting both orientations
On Oct 4, 2013, at 1:52 PM, David Hoerl dho...@mac.com wrote: But its really odd - and I'm thinking about a bug report on this - that the delegate has to provide the size before the view is even created. It make sense if you think about it: it's asking for sizes so that scroll view contentSize can be set and the layout can be determined. It would be a lot more expensive to have to actually build each of the cells for the entire collection just to get their sizes. This sort of behavior also happens with UITableView and its various cells. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to get variably sized header in a UICollectionView supporting both orientations
On 10/4/13 5:09 PM, Steve Christensen wrote: On Oct 4, 2013, at 1:52 PM, David Hoerl dho...@mac.com wrote: But its really odd - and I'm thinking about a bug report on this - that the delegate has to provide the size before the view is even created. It make sense if you think about it: it's asking for sizes so that scroll view contentSize can be set and the layout can be determined. It would be a lot more expensive to have to actually build each of the cells for the entire collection just to get their sizes. This sort of behavior also happens with UITableView and its various cells. In the old days, you had static views. Now with dynamic type, and the ability to more easily support different dynamic portrait/landscape layouts (with autolayout), the views can change a lot. Also, for table headers and footers, you created the view then set or returned it. With Collections you have to dequeue it, and ostensibly you can only do this when asked for a cell (since there is no way I know to dequeue a view then tell the collection that you don't really need it after all). Maybe I could dequeue one early on, cache it to get the sizes, and the first time only I'm asked for the view, return the cached one (then nil out the reference). This seems like it might work but IMHO would be risky in terms of stretching the API. I will probably at least try that out when I get everything else working. David ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
UICollectionView with NSFetchedResultsController; compatible?
I just finished watching Marcus Zarra's NSFetchedResultsController presentation from iDeveloper.tv . At about 25 minutes into the presentation, Marcus says the NSFetchedResultsController only works well with table-view controllers. I had planned to use it with a collection-view, which is why I reviewed the presentation in the first place. What I'm looking for is more information on why it is not a good idea to mix these two classes. What are the issues or pitfalls, in combining the two? I did find think link to a project on GitHub where the author points out that: The trick is to queue the updates made through the NSFetchedResultsControllerDelegate until the controller finishes its updates. UICollectionView doesn't have the same beginUpdates and endUpdates that UITableView has to let it work easily with NSFetchedResultsController, so you have to queue them or you get internal consistency runtime exceptions. Is this the only issue or are there other reasons to avoid combining these two types of controllers? -Michael ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
UICollectionView
Given an array of UIImages as a data source I want to populate a UICollection with these images. If I call -reloadData I see nothing in the view until the data source is exhausted then the view is displayed will all images. How can the UICollectionView be told to display each cell / image as it is created? I want the user to see that something is happening. -koko ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: UICollectionView
On May 8, 2013, at 11:06 AM, koko k...@highrolls.net wrote: Given an array of UIImages as a data source I want to populate a UICollection with these images. If I call -reloadData I see nothing in the view until the data source is exhausted then the view is displayed will all images. How can the UICollectionView be told to display each cell / image as it is created? I want the user to see that something is happening. Is the data source actually updating with new information? From the symptoms it sounds like that is not the case, and that it doesn't update until you've finished loading all of the images. -- David Duncan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com