public override void PrepareLayout() { isPreparing = true; layoutCache = new List <UICollectionViewLayoutAttributes>(); var numberOfItems = CollectionView.NumberOfItemsInSection(0); nfloat currentY = 0; for (var i = 0; i < numberOfItems; i++) { var viewSource = CollectionView.Source as ChatCollectionViewSource; var indexPath = NSIndexPath.FromItemSection(i, 0); var cell = viewSource.GetCell(CollectionView, indexPath) as ChatMessageCollectionViewCell; var size = cell.ContentView.SystemLayoutSizeFittingSize(UIScreen.MainScreen.Bounds.Size); CGRect frame = new CGRect { X = 0, Y = currentY, Width = size.Width, Height = size.Height, }; var attributes = UICollectionViewLayoutAttributes.CreateForCell(indexPath); attributes.Frame = frame; layoutCache.Add(attributes); currentY += frame.Height; } contentHeight = currentY; isPreparing = false; }
PointF CalculateTranslateBy(double horizontalCenter, UICollectionViewLayoutAttributes layout) { var translateByY = -layout.Frame.Height/2.0f; var distanceFromCenter = layout.Center.X - horizontalCenter; return new PointF((float)distanceFromCenter, translateByY); }
public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CoreGraphics.CGRect rect) { var arr = base.LayoutAttributesForElementsInRect(rect); if (arr.Length > 0) { UICollectionViewLayoutAttributes currentOne = arr[0]; CGRect frame = currentOne.Frame; frame.X = 0; currentOne.Frame = frame; } for (int i = 1; i < arr.Length; ++i) { UICollectionViewLayoutAttributes currentLayoutAttributes = arr[i]; UICollectionViewLayoutAttributes prevLayoutAttributes = arr[i - 1]; nfloat origin = prevLayoutAttributes.Frame.GetMaxX(); if (origin + maxCellSpacing + currentLayoutAttributes.Frame.Size.Width < CollectionView.ContentSize.Width) { CGRect frame = currentLayoutAttributes.Frame; frame.X = origin + maxCellSpacing; currentLayoutAttributes.Frame = frame; } else { CGRect frame = currentLayoutAttributes.Frame; frame.X = 0; currentLayoutAttributes.Frame = frame; } } return(arr); }
public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect) { var layoutAttributesForRectElements = base.LayoutAttributesForElementsInRect(rect); if (!NeedsPartialColumnAdjustment()) { return(layoutAttributesForRectElements); } // When we implement Groups, we'll have to iterate over all of them to adjust and this will // be a lot more complicated. But until then, we only have to worry about section 0 var section = 0; var itemCount = CollectionView.NumberOfItemsInSection(section); if (layoutAttributesForRectElements.Length == itemCount) { return(layoutAttributesForRectElements); } var layoutAttributesForAllCells = new UICollectionViewLayoutAttributes[itemCount]; layoutAttributesForRectElements.CopyTo(layoutAttributesForAllCells, 0); for (int i = layoutAttributesForRectElements.Length; i < layoutAttributesForAllCells.Length; i++) { layoutAttributesForAllCells[i] = LayoutAttributesForItem(NSIndexPath.FromItemSection(i, section)); } return(layoutAttributesForAllCells); }
public static void LeftAlignFrame(this UICollectionViewLayoutAttributes attributes, UIEdgeInsets sectionInsets) { CGRect frame = attributes.Frame; frame.X = sectionInsets.Left; attributes.Frame = frame; }
PointF CalculateTranslateBy(double horizontalCenter, UICollectionViewLayoutAttributes layout) { var translateByY = -layout.Frame.Height / 2.0f; var distanceFromCenter = layout.Center.X - horizontalCenter; return(new PointF((float)distanceFromCenter, translateByY)); }
public override UICollectionViewLayoutAttributes LayoutAttributesForDecorationView(NSString kind, NSIndexPath indexPath) { var layoutAttributes = UICollectionViewLayoutAttributes.CreateForDecorationView <FastListViewLayoutAttributes>(kind, indexPath); layoutAttributes.Color = _fastListView.SeparatorColor.ToUIColor(); return(layoutAttributes); }
public override bool ShouldInvalidateLayout(UICollectionViewLayoutAttributes preferredAttributes, UICollectionViewLayoutAttributes originalAttributes) { if (ItemSizingStrategy == ItemSizingStrategy.MeasureAllItems) { if (preferredAttributes.Bounds != originalAttributes.Bounds) { return(true); } } if (Forms.IsiOS11OrNewer) { return(base.ShouldInvalidateLayout(preferredAttributes, originalAttributes)); } // For iOS 10 and lower, we have to invalidate on header/footer changes here; otherwise, all of the // headers and footers will draw on top of one another if (preferredAttributes.RepresentedElementKind == UICollectionElementKindSectionKey.Header || preferredAttributes.RepresentedElementKind == UICollectionElementKindSectionKey.Footer) { return(true); } return(base.ShouldInvalidateLayout(preferredAttributes, originalAttributes)); }
private void LayoutSectionHeader(Dictionary <string, LayoutInfo> layoutInfos, int section, ref CGRect frame) { if (ScrollDirection == ListViewBaseScrollDirection.Horizontal) { throw new NotImplementedException("The section header for a horizontal listview is not implemented."); } var createLayoutInfo = layoutInfos != null; if (section > 0) { frame.Y += IntersectionSpacing; } var sectionHeaderSize = GetSectionHeaderSize(); frame.Height = sectionHeaderSize.Height; if (createLayoutInfo) { var sectionHeaderLayoutInfo = layoutInfos.FindOrCreate(ListViewBase.ListViewSectionHeaderElementKind, () => new LayoutInfo()); //indexPath acts to uniquely identify this instance of ListViewSectionHeaderElementKind (one per section) var indexPath = NSIndexPath.FromRowSection(0, section); var layoutAttributes = UICollectionViewLayoutAttributes. CreateForSupplementaryView <UICollectionViewLayoutAttributes>(ListViewBase.ListViewSectionHeaderElementKindNS, indexPath); layoutAttributes.Frame = new CGRect(Margin.Left, frame.Y, frame.Width, sectionHeaderSize.Height); sectionHeaderLayoutInfo[indexPath] = layoutAttributes; } frame.Y += frame.Height + LineSpacing; }
public override UICollectionViewLayoutAttributes LayoutAttributesForSupplementaryView(NSString kind, NSIndexPath indexPath) { var attrs = UICollectionViewLayoutAttributes.CreateForSupplementaryView(kind, indexPath); attrs.Frame = new CGRect(0, 0, CollectionView.Frame.Width, Header.HeightRequest); return(attrs); }
static bool IsAtLeastHalfVisible(UICollectionViewLayoutAttributes item, CGRect viewport) { var itemFrame = item.Frame; var visibleArea = Area(CGRect.Intersect(itemFrame, viewport)); return(visibleArea >= Area(itemFrame) / 2); }
/// <summary> /// Adjusts the size of the frame by calculating the required space of the header. /// </summary> private void LayoutHeader(Dictionary <string, LayoutInfo> layoutInfos, ref CGRect frame) { if (ScrollDirection == ListViewBaseScrollDirection.Horizontal) { throw new NotImplementedException("The header for an horizontal listview is not implemented."); } var createLayoutInfo = layoutInfos != null; var headerSize = GetHeaderSize(); frame.Height = headerSize.Height; if (createLayoutInfo) { var headerLayoutInfo = new LayoutInfo(); //"It is up to you to decide how to use the indexPath parameter to identify a given supplementary view. Typically, you use the elementKind parameter to identify the type //of the supplementary view and the indexPath information to distinguish between different instances of that view." //https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionViewLayoutAttributes_class/#//apple_ref/occ/clm/UICollectionViewLayoutAttributes/layoutAttributesForSupplementaryViewOfKind:withIndexPath: var indexPath = NSIndexPath.FromRowSection(0, 0); var layoutAttributes = UICollectionViewLayoutAttributes.CreateForSupplementaryView <UICollectionViewLayoutAttributes>(ListViewBase.ListViewHeaderElementKindNS, indexPath); layoutAttributes.Frame = new CGRect(Margin.Left, frame.Y, frame.Width, headerSize.Height); headerLayoutInfo[indexPath] = layoutAttributes; layoutInfos[ListViewBase.ListViewHeaderElementKind] = headerLayoutInfo; } frame.Y += frame.Height + LineSpacing; }
/// <summary> /// Adjusts the size of the frame by calculating the required space of the footer. /// </summary> private void LayoutFooter(Dictionary <string, LayoutInfo> layoutInfos, ref CGRect frame) { if (ScrollDirection == ListViewBaseScrollDirection.Horizontal) { throw new NotImplementedException("The footer for an horizontal listview is not implemented."); } var createLayoutInfo = layoutInfos != null; var footerSize = GetFooterSize(); frame.Height = footerSize.Height; if (createLayoutInfo) { var footerLayoutInfo = new LayoutInfo(); var indexPath = NSIndexPath.FromRowSection(0, 0); var layoutAttributes = UICollectionViewLayoutAttributes.CreateForSupplementaryView <UICollectionViewLayoutAttributes>(ListViewBase.ListViewFooterElementKindNS, indexPath); layoutAttributes.Frame = new CGRect(Margin.Left, frame.Y, frame.Width, footerSize.Height); footerLayoutInfo[indexPath] = layoutAttributes; layoutInfos[ListViewBase.ListViewFooterElementKind] = footerLayoutInfo; } frame.Y += frame.Height + LineSpacing; }
public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect) { if (!NeedsPartialColumnAdjustment()) { return(base.LayoutAttributesForElementsInRect(rect)); } // When we implement Groups, we'll have to iterate over all of them to adjust and this will // be a lot more complicated. But until then, we only have to worry about section 0 int section = 0; var fullColumns = base.LayoutAttributesForElementsInRect(rect); var itemCount = CollectionView.NumberOfItemsInSection(section); if (fullColumns.Length == itemCount) { return(fullColumns); } var missingCellCount = itemCount % _itemsLayout.Span; UICollectionViewLayoutAttributes[] allCells = new UICollectionViewLayoutAttributes[fullColumns.Length + missingCellCount]; fullColumns.CopyTo(allCells, 0); for (int n = fullColumns.Length; n < allCells.Length; n++) { allCells[n] = LayoutAttributesForItem(NSIndexPath.FromItemSection(n, section)); } return(allCells); }
void CenterAlignCellsInColumn(UICollectionViewLayoutAttributes preferredAttributes) { // Determine the set of cells above this one var index = preferredAttributes.IndexPath; var span = _itemsLayout.Span; var column = index.Item / span; var start = (int)column * span; // If this is the first cell in the column, we don't need to adjust if (index.Item > start) { var currentCenter = preferredAttributes.Frame.GetMidX(); // Work our way through the column for (int n = start; n < index.Item; n++) { // Get the layout attributes for each cell var path = NSIndexPath.FromItemSection(n, index.Section); var attr = LayoutAttributesForItem(path); // And see if the midpoints line up with the new layout attributes for the current cell var center = attr.Frame.GetMidX(); if (currentCenter - center > 1) { // If the midpoints don't line up (withing a tolerance), adjust the cell's frame var cell = CollectionView.CellForItem(path); cell.Frame = new CGRect(currentCenter - cell.Frame.Width / 2, cell.Frame.Top, cell.Frame.Width, cell.Frame.Height); } } } }
public void UpdateSelectedBarPosition(bool animated, SwipeDirection swipeDirection, PagerScroll pagerScroll) { var selectedBarFrame = SelectedBar.Frame; NSIndexPath selectedCellIndexPath = NSIndexPath.FromItemSection(new nint(selectedIndex), 0); UICollectionViewLayoutAttributes attributes = GetLayoutAttributesForItem(selectedCellIndexPath); CGRect selectedCellFrame = attributes.Frame; UpdateContentOffset(animated, pagerScroll: pagerScroll, toFrame: selectedCellFrame, toIndex: selectedCellIndexPath.Row); if (this.SelectedBarWidth.HasValue) { selectedBarFrame.Size = new CGSize(this.SelectedBarWidth.Value, selectedBarFrame.Height); selectedBarFrame.X = selectedCellFrame.X + (selectedCellFrame.Width - this.SelectedBarWidth.Value) / 2; } else { selectedBarFrame.Size = new CGSize(selectedCellFrame.Width, selectedBarFrame.Height); selectedBarFrame.X = selectedCellFrame.X; } if (animated) { UIView.Animate(0.3, () => { SelectedBar.Frame = selectedBarFrame; }); } else { SelectedBar.Frame = selectedBarFrame; } }
/// <summary> /// Layouts the attributes for elements in rect. /// </summary> /// <returns>The attributes for elements in rect.</returns> /// <param name="rect">Rect.</param> public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect) { var attributes = new UICollectionViewLayoutAttributes[_cellCount + 1]; CalculateAllAttributes(attributes); if (_requiresHeightCalculation) { CalculateHeightForItems(); CalculateAllAttributes(attributes); } // we must set the content size to the total height of all cells recorded in _currentY var width = _collectionViewSize.Width; _collectionViewSize = new CGSize(width, _currentHeight); var decorationAttribs = UICollectionViewLayoutAttributes.CreateForDecorationView(myDecorationViewId, NSIndexPath.FromItemSection(0, 0)); decorationAttribs.Size = new CGSize(CollectionView.Frame.Width, CollectionView.Frame.Height); decorationAttribs.ZIndex = -1; attributes[_cellCount] = decorationAttribs; return(attributes); }
public override void ApplyLayoutAttributes(UICollectionViewLayoutAttributes layoutAttributes) { var attributes = layoutAttributes as FastListViewLayoutAttributes; this.Frame = attributes.Frame; this.BackgroundColor = attributes.Color; }
public void applyPinchToLayoutAttributes (UICollectionViewLayoutAttributes layoutAttributes) { if (layoutAttributes.IndexPath.Equals (pinchedCellPath)) { layoutAttributes.Transform3D = CATransform3D.MakeScale (pinchedCellScale, pinchedCellScale, 1.0f); layoutAttributes.Center = pinchedCellCenter; layoutAttributes.ZIndex = 1; } }
public override UICollectionViewLayoutAttributes LayoutAttributesForItem(NSIndexPath indexPath) { UICollectionViewLayoutAttributes attributes = base.LayoutAttributesForItem(indexPath); CGPoint center = attributes.Center; attributes.Center = new CGPoint(center.X + Offset.Horizontal, center.Y + Offset.Vertical); return(attributes); }
public override UICollectionViewLayoutAttributes LayoutAttributesForItem(NSIndexPath path) { UICollectionViewLayoutAttributes attributes = UICollectionViewLayoutAttributes.CreateForCell(path); attributes.Size = new CGSize(ItemSize, ItemSize); attributes.Center = new CGPoint( _center.X + _radius * (float)Math.Cos(2 * path.Row * Math.PI / _cellCount), _center.Y + _radius * (float)Math.Sin(2 * path.Row * Math.PI / _cellCount)); return attributes; }
public void applyPinchToLayoutAttributes(UICollectionViewLayoutAttributes layoutAttributes) { if (layoutAttributes.IndexPath.Equals(pinchedCellPath)) { layoutAttributes.Transform3D = CATransform3D.MakeScale(pinchedCellScale, pinchedCellScale, 1.0f); layoutAttributes.Center = pinchedCellCenter; layoutAttributes.ZIndex = 1; } }
public override UICollectionViewLayoutAttributes LayoutAttributesForItem(NSIndexPath path) { UICollectionViewLayoutAttributes attributes = UICollectionViewLayoutAttributes.CreateForCell(path); attributes.Size = new SizeF(ItemSize, ItemSize); attributes.Center = new PointF(center.X + radius * (float)Math.Cos(2 * path.Row * Math.PI / cellCount), center.Y + radius * (float)Math.Sin(2 * path.Row * Math.PI / cellCount)); return(attributes); }
public override CGPoint TargetContentOffset(CGPoint proposedContentOffset, CGPoint scrollingVelocity) { if (CollectionView == null) { return(proposedContentOffset); } var collectionViewSize = CollectionView.Bounds.Size; var proposedRect = new CGRect(proposedContentOffset.X, 0, collectionViewSize.Width, collectionViewSize.Height); var layoutAttributes = LayoutAttributesForElementsInRect(proposedRect); if (layoutAttributes == null) { return(proposedContentOffset); } UICollectionViewLayoutAttributes candidateAttributes = null; var proposedContentOffsetCenterX = proposedContentOffset.X + collectionViewSize.Width / 2; foreach (var attributes in layoutAttributes) { if (attributes.RepresentedElementCategory != UICollectionElementCategory.Cell) { continue; } if (candidateAttributes == null) { candidateAttributes = attributes; continue; } if (Math.Abs(attributes.Center.X - proposedContentOffsetCenterX) < Math.Abs(candidateAttributes.Center.X - proposedContentOffsetCenterX)) { candidateAttributes = attributes; } } if (candidateAttributes == null) { return(proposedContentOffset); } var newOffsetX = candidateAttributes.Center.X - CollectionView.Bounds.Size.Width / 2; var offset = newOffsetX - CollectionView.ContentOffset.X; if ((scrollingVelocity.X < 0 && offset > 0) || (scrollingVelocity.X > 0 && offset < 0)) { var pageWidth = ItemSize.Width + MinimumLineSpacing; newOffsetX += scrollingVelocity.X > 0 ? pageWidth : -pageWidth; } return(new CGPoint(newOffsetX, proposedContentOffset.Y)); }
// return layout attributes for a a specific item public override UICollectionViewLayoutAttributes LayoutAttributesForItem(NSIndexPath path) { UICollectionViewLayoutAttributes attributes = UICollectionViewLayoutAttributes.CreateForCell(path); attributes.Size = ItemSize; attributes.Center = new PointF(center.X + radius * (float)Math.Cos(2 * path.Row * Math.PI / count), center.Y + radius * (float)Math.Sin(2 * path.Row * Math.PI / count)); attributes.Transform3D = CATransform3D.MakeScale(0.5f, 0.5f, 1.0f); return(attributes); }
private void CreateSectionHeaderLayoutInfo(Dictionary <NSIndexPath, UICollectionViewLayoutAttributes> headerLayoutInfo, int section, CGRect sectionHeaderFrame) { var indexPath = GetNSIndexPathFromRowSection(0, section); var layoutAttributes = UICollectionViewLayoutAttributes .CreateForSupplementaryView <UICollectionViewLayoutAttributes>(ListViewBase.ListViewSectionHeaderElementKindNS, indexPath); layoutAttributes.Frame = sectionHeaderFrame; headerLayoutInfo[indexPath] = layoutAttributes; _inlineHeaderFrames[section] = sectionHeaderFrame; }
// TODO: Step 5c: add layout attributes for decoration view public override UICollectionViewLayoutAttributes LayoutAttributesForDecorationView(NSString kind, NSIndexPath indexPath) { var decorationAttribs = UICollectionViewLayoutAttributes.CreateForDecorationView(kind, indexPath); decorationAttribs.Size = CollectionView.Frame.Size; decorationAttribs.Center = CollectionView.Center; decorationAttribs.ZIndex = -1; return(decorationAttribs); }
private static bool FindItemAttributes(UICollectionViewLayoutAttributes attribute) { if (rectForLayoutAttributes.IntersectsWith(attribute.Frame)) { return(true); } else { return(false); } }
public override void ApplyLayoutAttributes (UICollectionViewLayoutAttributes layoutAttributes) { var attributes = layoutAttributes as CustomCollectionViewLayoutAttributes; if (attributes != null) { var data = attributes.Data; attributes.Center = new PointF (data.Center.X + data.Radius * attributes.Distance * (float) Math.Cos (2 * attributes.Row * Math.PI / data.CellCount), data.Center.Y + data.Radius * attributes.Distance * (float) Math.Sin (2 * attributes.Row * Math.PI / data.CellCount)); } base.ApplyLayoutAttributes (layoutAttributes); }
public override void ApplyLayoutAttributes(UICollectionViewLayoutAttributes layoutAttributes) { base.ApplyLayoutAttributes(layoutAttributes); nfloat featuredHeight = (nfloat)CompetitionLayout.CompetitionFeaturedHeight; nfloat standardHeight = (nfloat)CompetitionLayout.CompetitionStandardHeight; nfloat delta = 1 - ((featuredHeight - this.Frame.Height) / (featuredHeight - standardHeight)); CompetitionStageHolder.Alpha = delta; }
void HandleDownloadEvent(LibraryBookView bookView) { try { if (!downloadAnimation) { downloadAnimation = true; // Remove from collectionView bookView.RemoveFromSuperview(); // Add to the current view at exact position NSIndexPath indexPath = dataSource.GetIndexPath(bookView.LibraryBook.ID); UICollectionViewLayoutAttributes attributes = collectionView.GetLayoutAttributesForItem(indexPath); bookView.Frame = new CGRect(attributes.Frame.X + collectionView.Frame.X, attributes.Frame.Y - collectionView.ContentOffset.Y, attributes.Frame.Width, attributes.Frame.Height); this.View.AddSubview(bookView); // Fly Animation CGPoint startPoint = new CGPoint(bookView.Frame.X + bookView.Frame.Width / 2, bookView.Frame.Y + bookView.Frame.Height / 2); CGPoint endPoint = new CGPoint(Settings.MyBooksTabLocation.X + 76f / 2f, this.View.Frame.Bottom + 55f / 2f); UIView.Animate(0.75d, delegate { bookView.Transform = CGAffineTransform.MakeScale(0.1f, 0.1f); bookView.Center = endPoint; bookView.Alpha = 0.5f; // Prepare my own keypath animation for the layer position CGPath animationPath = CreatePath(startPoint, endPoint); CAKeyFrameAnimation keyFrameAnimation = CAKeyFrameAnimation.GetFromKeyPath("position"); keyFrameAnimation.Path = animationPath; // Copy properties from UIView's animation CAAnimation autoAnimation = bookView.Layer.AnimationForKey("position"); keyFrameAnimation.Duration = autoAnimation.Duration; keyFrameAnimation.FillMode = autoAnimation.FillMode; keyFrameAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut); // Replace UIView's animation with my animation bookView.Layer.AddAnimation(keyFrameAnimation, keyFrameAnimation.KeyPath); }, delegate { this.InvokeOnMainThread(delegate { UpdateCollectionView(bookView); }); }); } } catch (Exception ex) { Logger.WriteLineDebugging("LibraryViewController - HandleDownloadEvent: {0}", ex.ToString()); } }
public override UICollectionViewLayoutAttributes LayoutAttributesForSupplementaryView(NSString kind, NSIndexPath indexPath) { if (Forms.IsiOS11OrNewer) { return(base.LayoutAttributesForSupplementaryView(kind, indexPath)); } // iOS 10 and lower doesn't create these and will throw an exception in GetViewForSupplementaryElement // without them, so we need to do it manually here return(UICollectionViewLayoutAttributes.CreateForSupplementaryView(kind, indexPath)); }
public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect (RectangleF rect) { var attributes = new UICollectionViewLayoutAttributes [cellCount]; for (int i = 0; i < cellCount; i++) { NSIndexPath indexPath = NSIndexPath.FromItemSection (i, 0); attributes [i] = LayoutAttributesForItem (indexPath); } return attributes; }
// return layout attributes for all the items in a given rectangle public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(RectangleF rect) { UICollectionViewLayoutAttributes[] attributes = new UICollectionViewLayoutAttributes [count]; for (int i = 0; i < count; i++) { NSIndexPath indexPath = NSIndexPath.FromItemSection(i, 0); attributes [i] = LayoutAttributesForItem(indexPath); } return(attributes); }
public override void ApplyLayoutAttributes(UICollectionViewLayoutAttributes layoutAttributes) { var attributes = layoutAttributes as CustomCollectionViewLayoutAttributes; if (attributes != null) { var data = attributes.Data; attributes.Center = new CGPoint (data.Center.X + data.Radius * attributes.Distance * (float) Math.Cos (2 * attributes.Row * Math.PI / data.CellCount), data.Center.Y + data.Radius * attributes.Distance * (float) Math.Sin (2 * attributes.Row * Math.PI / data.CellCount)); if (!float.IsNaN ((float)attributes.Center.X) && !float.IsNaN ((float)attributes.Center.Y) && UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) Center = attributes.Center; } base.ApplyLayoutAttributes (layoutAttributes); }
// return layout attributes for all the items in a given rectangle public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect (RectangleF rect) { UICollectionViewLayoutAttributes[] attributes = new UICollectionViewLayoutAttributes [count]; // TODO: Step 5d: add an attributes entry for the Decoration View // UICollectionViewLayoutAttributes[] attributes = new UICollectionViewLayoutAttributes [count + 1]; for (int i = 0; i < count; i++) { NSIndexPath indexPath = NSIndexPath.FromItemSection (i, 0); attributes [i] = LayoutAttributesForItem (indexPath); } // TODO: Step 5e: set the layout attributes for the Decoration View // attributes [count] = LayoutAttributesForDecorationView (decorationViewId, NSIndexPath.FromItemSection (0, 0)); return attributes; }
public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect (RectangleF rect) { var attributes = new UICollectionViewLayoutAttributes [cellCount + 1]; for (int i = 0; i < cellCount; i++) { NSIndexPath indexPath = NSIndexPath.FromItemSection (i, 0); attributes [i] = LayoutAttributesForItem (indexPath); } var decorationAttribs = UICollectionViewLayoutAttributes.CreateForDecorationView (myDecorationViewId, NSIndexPath.FromItemSection (0, 0)); decorationAttribs.Size = rect.Size; decorationAttribs.Center = CollectionView.Center; decorationAttribs.ZIndex = -1; attributes [cellCount] = decorationAttribs; return attributes; }
public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(RectangleF rect) { int n = count * 2 + 1; var attributes = new UICollectionViewLayoutAttributes [n]; //assume same number of players on each team for (int i = 0; i < count; i++) { var indexPath = NSIndexPath.FromItemSection (i, 0); attributes [i] = LayoutAttributesForItem (indexPath); var indexPath2 = NSIndexPath.FromItemSection (i, 1); attributes [i+count] = LayoutAttributesForItem (indexPath2); } // add layout attributes for decoration view attributes [n-1] = LayoutAttributesForDecorationView (baseFieldDecorationId, NSIndexPath.FromItemSection (0, 0)); return attributes; }
public override void ViewDidLoad () { base.ViewDidLoad (); // Perform any additional setup after loading the view, typically from a nib. var a1 = new UICollectionViewLayoutAttributes () { Center = new CGPoint (1, 2) }; var a2 = a1.Copy (); Console.WriteLine ("a1 IsEqual a2 = {0}", a2.IsEqual(a1)); var attr = new MyCollectionViewGridLayoutAttributes { BackgroundColor = UIColor.Red }; var cloneArrt = (MyCollectionViewGridLayoutAttributes)attr.Clone (); Console.WriteLine ("cloneArrt.Equals(attr) = {0}", cloneArrt.Equals(attr)); }
public override void ApplyLayoutAttributes(UICollectionViewLayoutAttributes layoutAttributes) { base.ApplyLayoutAttributes (layoutAttributes); BackgroundColor = ((CustomDecorationViewLayoutAttributes)layoutAttributes).DecorationColor; }
/// <summary> /// Should fix choppy scrolling on ios8+ by preventing a layout pass when autolayout is already computed /// /// iOS 8 provides a new self-sizing API for CollectionView and CollectionViewCells. It lets cells determine their own height, based on the content that they're about to load. /// preferredLayoutAttributesFittingAttributes: (on the cell) /// shouldLayoutAttributesFittingAttributes: (on the layout) /// invalidationContextForPreferredLayoutAttributes:withOriginalAttributes: (on the layout) /// </summary> public override UICollectionViewLayoutAttributes PreferredLayoutAttributesFittingAttributes(UICollectionViewLayoutAttributes layoutAttributes) { return layoutAttributes; }
public override void PrepareLayout () { base.PrepareLayout (); // Get the number of sections var numberofSections = CollectionView.NumberOfSections (); if (numberofSections == 0) return; // Reset collections headersAttributes.Clear (); footersAttributes.Clear (); unionRects.Clear (); columnHeights.Clear (); allItemAttributes.Clear (); sectionItemAttributes.Clear (); // Initialize column heights for (int n = 0; n < ColumnCount; n++) columnHeights.Add ((nfloat)0); // Process all sections nfloat top = 0f; var attributes = new UICollectionViewLayoutAttributes (); int columnIndex = 0; for (nint section = 0; section < numberofSections; ++section) { // Calculate widths var width = CollectionView.Bounds.Width - SectionInset.Left - SectionInset.Right; var itemWidth = (nfloat)Math.Floor ((width - ((ColumnCount - 1) * MinimumColumnSpacing)) / ColumnCount); // Calculate section header var heightHeader = (HeightForHeader == null) ? HeaderHeight : HeightForHeader (CollectionView, this, section); if (heightHeader > 0) { attributes = UICollectionViewLayoutAttributes.CreateForSupplementaryView (UICollectionElementKindSection.Header, NSIndexPath.FromRowSection (0, section)); attributes.Frame = new CGRect (0, top, CollectionView.Bounds.Width, heightHeader); headersAttributes.Add (section, attributes); allItemAttributes.Add (attributes); top = attributes.Frame.GetMaxY (); } top += SectionInset.Top; for (int n = 0; n < ColumnCount; n++) columnHeights [n] = top; // Calculate Section Items var itemCount = CollectionView.NumberOfItemsInSection (section); var itemAttributes = new List<UICollectionViewLayoutAttributes> (); for (nint n = 0; n < itemCount; n++) { var indexPath = NSIndexPath.FromRowSection (n, section); columnIndex = NextColumnIndexForItem (n); var xOffset = SectionInset.Left + (itemWidth + MinimumColumnSpacing) * (nfloat)columnIndex; var yOffset = columnHeights [columnIndex]; var itemSize = (SizeForItem == null) ? new CGSize (0, 0) : SizeForItem (CollectionView, this, indexPath); nfloat itemHeight = 0.0f; if (itemSize.Height > 0.0f && itemSize.Width > 0.0f) itemHeight = (nfloat)Math.Floor (itemSize.Height * itemWidth / itemSize.Width); attributes = UICollectionViewLayoutAttributes.CreateForCell (indexPath); attributes.Frame = new CGRect (xOffset, yOffset, itemWidth, itemHeight); itemAttributes.Add (attributes); allItemAttributes.Add (attributes); columnHeights [columnIndex] = attributes.Frame.GetMaxY () + MinimumInterItemSpacing; } sectionItemAttributes.Add (itemAttributes); // Calculate Section Footer columnIndex = LongestColumnIndex (); top = columnHeights [columnIndex] - MinimumInterItemSpacing + SectionInset.Bottom; footerHeight = (HeightForFooter == null) ? FooterHeight : HeightForFooter (CollectionView, this, section); if (footerHeight > 0) { attributes = UICollectionViewLayoutAttributes.CreateForSupplementaryView (UICollectionElementKindSection.Footer, NSIndexPath.FromRowSection (0, section)); attributes.Frame = new CGRect (0, top, CollectionView.Bounds.Width, footerHeight); footersAttributes.Add (section, attributes); allItemAttributes.Add (attributes); top = attributes.Frame.GetMaxY (); } for (int n = 0; n < ColumnCount; n++) columnHeights [n] = top; } int i = 0; int attrs = allItemAttributes.Count; while (i < attrs) { var rect1 = allItemAttributes [i].Frame; i = (int)Math.Min (i + unionSize, attrs) - 1; var rect2 = allItemAttributes [i].Frame; unionRects.Add (CGRect.Union (rect1, rect2)); i++; } }
public override UICollectionViewLayoutAttributes LayoutAttributesForSupplementaryView (NSString kind, NSIndexPath indexPath) { var attributes = new UICollectionViewLayoutAttributes (); switch (kind) { case "header": attributes = headersAttributes [indexPath.Section]; break; case "footer": attributes = footersAttributes [indexPath.Section]; break; } return attributes; }
void PaintItem(UICollectionViewLayoutAttributes attributes,SizeF currentSize, int rowspan, int colspan) { //we need another column if (currentRow+rowspan > nRows) { currentColumn++; currentRow = 0; } bool keepLooping = true; bool canDraw = true; for (int i = currentRow; i < currentRow + rowspan && keepLooping; i++) { for (int j = currentColumn; j < currentColumn + colspan; j++) { var exists = matrix.FirstOrDefault (c => c.Key.Key == i && c.Key.Value == j); if(canDraw) canDraw = !exists.Value; } } if (canDraw) { for (int i = currentRow; i < currentRow + rowspan; i++) { for (int j = currentColumn; j < currentColumn + colspan; j++) { matrix.Add (new KeyValuePair<int, int> (i, j), true); } } var x = (currentColumn * ItemSize.Width) + (currentSize.Width / 2) + (Margin * (currentColumn + 1)); var y = ((currentRow) * rowH) + (currentSize.Height / 2) + (Margin * (currentRow)); attributes.Center = new PointF ((float)x, (float)y); currentRow += rowspan; } else { currentRow++; PaintItem (attributes, currentSize, rowspan, colspan); } }