SimpleCollectionView Sample ported to 64-bits

This commit is contained in:
Paola Villarreal 2014-07-28 13:17:01 -05:00
Родитель b717bc33e8
Коммит 5f99e65ef1
9 изменённых файлов: 68 добавлений и 65 удалений

Просмотреть файл

@ -2,9 +2,9 @@ using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Drawing;
using Foundation;
using UIKit;
using CoreGraphics;
namespace SimpleCollectionView
{
@ -24,7 +24,7 @@ namespace SimpleCollectionView
// Flow Layout
flowLayout = new UICollectionViewFlowLayout (){
HeaderReferenceSize = new System.Drawing.SizeF (100, 100),
HeaderReferenceSize = new CoreGraphics.CGSize (100, 100),
SectionInset = new UIEdgeInsets (20,20,20,20),
ScrollDirection = UICollectionViewScrollDirection.Vertical,
MinimumInteritemSpacing = 50, // minimum spacing between cells
@ -33,7 +33,7 @@ namespace SimpleCollectionView
// Line Layout
lineLayout = new LineLayout (){
HeaderReferenceSize = new System.Drawing.SizeF (160, 100),
HeaderReferenceSize = new CoreGraphics.CGSize (160, 100),
ScrollDirection = UICollectionViewScrollDirection.Horizontal
};

Просмотреть файл

@ -1,18 +1,18 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.CoreAnimation;
using MonoTouch.UIKit;
using CoreGraphics;
using Foundation;
using CoreAnimation;
using UIKit;
namespace SimpleCollectionView
{
public class CircleLayout : UICollectionViewLayout
{
const float ItemSize = 70.0f;
int cellCount = 20;
float radius;
PointF center;
nint cellCount = 20;
nfloat radius;
CGPoint center;
static NSString myDecorationViewId = new NSString ("MyDecorationView");
@ -25,19 +25,19 @@ namespace SimpleCollectionView
{
base.PrepareLayout ();
SizeF size = CollectionView.Frame.Size;
CGSize size = CollectionView.Frame.Size;
cellCount = CollectionView.NumberOfItemsInSection (0);
center = new PointF (size.Width / 2.0f, size.Height / 2.0f);
radius = Math.Min (size.Width, size.Height) / 2.5f;
center = new CGPoint (size.Width / 2.0f, size.Height / 2.0f);
radius = (nfloat)Math.Min (size.Width, size.Height) / 2.5f;
}
public override SizeF CollectionViewContentSize {
public override CGSize CollectionViewContentSize {
get {
return CollectionView.Frame.Size;
}
}
public override bool ShouldInvalidateLayoutForBoundsChange (RectangleF newBounds)
public override bool ShouldInvalidateLayoutForBoundsChange (CGRect newBounds)
{
return true;
}
@ -45,13 +45,13 @@ namespace SimpleCollectionView
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),
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 override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect (RectangleF rect)
public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect (CGRect rect)
{
var attributes = new UICollectionViewLayoutAttributes [cellCount + 1];
@ -74,7 +74,7 @@ namespace SimpleCollectionView
public class MyDecorationView : UICollectionReusableView
{
[Export ("initWithFrame:")]
public MyDecorationView (System.Drawing.RectangleF frame) : base (frame)
public MyDecorationView (CoreGraphics.CGRect frame) : base (frame)
{
BackgroundColor = UIColor.Red;
}

Просмотреть файл

@ -1,7 +1,7 @@
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using CoreGraphics;
using Foundation;
using UIKit;
namespace SimpleCollectionView
{
@ -11,7 +11,7 @@ namespace SimpleCollectionView
{
}
public override bool ShouldInvalidateLayoutForBoundsChange (RectangleF newBounds)
public override bool ShouldInvalidateLayoutForBoundsChange (CGRect newBounds)
{
return true;
}
@ -21,12 +21,12 @@ namespace SimpleCollectionView
return base.LayoutAttributesForItem (path);
}
public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect (RectangleF rect)
public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect (CGRect rect)
{
return base.LayoutAttributesForElementsInRect (rect);
}
// public override SizeF CollectionViewContentSize {
// public override CGSize CollectionViewContentSize {
// get {
// return CollectionView.Bounds.Size;
// }

Просмотреть файл

@ -1,5 +1,5 @@
using System;
using MonoTouch.UIKit;
using UIKit;
namespace SimpleCollectionView
{

Просмотреть файл

@ -1,9 +1,9 @@
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using MonoTouch.CoreAnimation;
using CoreGraphics;
using Foundation;
using UIKit;
using CoreAnimation;
namespace SimpleCollectionView
{
@ -15,28 +15,28 @@ namespace SimpleCollectionView
public LineLayout ()
{
ItemSize = new SizeF (ITEM_SIZE, ITEM_SIZE);
ItemSize = new CGSize (ITEM_SIZE, ITEM_SIZE);
ScrollDirection = UICollectionViewScrollDirection.Horizontal;
SectionInset = new UIEdgeInsets (400,0,400,0);
MinimumLineSpacing = 50.0f;
}
public override bool ShouldInvalidateLayoutForBoundsChange (RectangleF newBounds)
public override bool ShouldInvalidateLayoutForBoundsChange (CGRect newBounds)
{
return true;
}
public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect (RectangleF rect)
public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect (CGRect rect)
{
var array = base.LayoutAttributesForElementsInRect (rect);
var visibleRect = new RectangleF (CollectionView.ContentOffset, CollectionView.Bounds.Size);
var visibleRect = new CGRect (CollectionView.ContentOffset, CollectionView.Bounds.Size);
foreach (var attributes in array) {
if (attributes.Frame.IntersectsWith (rect)) {
float distance = visibleRect.GetMidX () - attributes.Center.X;
float normalizedDistance = distance / ACTIVE_DISTANCE;
nfloat distance = visibleRect.GetMidX () - attributes.Center.X;
nfloat normalizedDistance = distance / ACTIVE_DISTANCE;
if (Math.Abs (distance) < ACTIVE_DISTANCE) {
float zoom = 1 + ZOOM_FACTOR * (1 - Math.Abs (normalizedDistance));
nfloat zoom = (nfloat)(1 + ZOOM_FACTOR * (1 - Math.Abs (normalizedDistance)));
attributes.Transform3D = CATransform3D.MakeScale (zoom, zoom, 1.0f);
attributes.ZIndex = 1;
}
@ -45,19 +45,19 @@ namespace SimpleCollectionView
return array;
}
public override PointF TargetContentOffset (PointF proposedContentOffset, PointF scrollingVelocity)
public override CGPoint TargetContentOffset (CGPoint proposedContentOffset, CGPoint scrollingVelocity)
{
float offSetAdjustment = float.MaxValue;
float horizontalCenter = (float)(proposedContentOffset.X + (this.CollectionView.Bounds.Size.Width / 2.0));
RectangleF targetRect = new RectangleF (proposedContentOffset.X, 0.0f, this.CollectionView.Bounds.Size.Width, this.CollectionView.Bounds.Size.Height);
nfloat offSetAdjustment = float.MaxValue;
nfloat horizontalCenter = (float)(proposedContentOffset.X + (this.CollectionView.Bounds.Size.Width / 2.0));
CGRect targetRect = new CGRect (proposedContentOffset.X, 0.0f, this.CollectionView.Bounds.Size.Width, this.CollectionView.Bounds.Size.Height);
var array = base.LayoutAttributesForElementsInRect (targetRect);
foreach (var layoutAttributes in array) {
float itemHorizontalCenter = layoutAttributes.Center.X;
nfloat itemHorizontalCenter = layoutAttributes.Center.X;
if (Math.Abs (itemHorizontalCenter - horizontalCenter) < Math.Abs (offSetAdjustment)) {
offSetAdjustment = itemHorizontalCenter - horizontalCenter;
}
}
return new PointF (proposedContentOffset.X + offSetAdjustment, proposedContentOffset.Y);
return new CGPoint (proposedContentOffset.X + offSetAdjustment, proposedContentOffset.Y);
}
}

Просмотреть файл

@ -2,8 +2,8 @@ using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using Foundation;
using UIKit;
namespace SimpleCollectionView
{

Просмотреть файл

@ -1,5 +1,5 @@
using System;
using MonoTouch.UIKit;
using UIKit;
namespace SimpleCollectionView
{

Просмотреть файл

@ -17,7 +17,7 @@
<DebugType>full</DebugType>
<Optimize>False</Optimize>
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<DefineConstants>DEBUG;XAMCORE_2_0;ARCH_64</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause>
@ -26,6 +26,7 @@
<MtouchLink>None</MtouchLink>
<MtouchArch>ARMv7</MtouchArch>
<MtouchI18n />
<MtouchExtraArgs>--registrar:static --nofastsim --override-abi x86_64</MtouchExtraArgs>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
@ -81,7 +82,9 @@
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="monotouch" />
<Reference Include="Xamarin.iOS">
<HintPath>\Developer\MonoTouch\usr\lib\mono\Xamarin.iOS\Xamarin.iOS.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
@ -125,4 +128,4 @@
<ItemGroup>
<ITunesArtwork Include="Resources\iTunesArtwork.png" />
</ItemGroup>
</Project>
</Project>

Просмотреть файл

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using MonoTouch.CoreGraphics;
using MonoTouch.ObjCRuntime;
using UIKit;
using Foundation;
using CoreGraphics;
using ObjCRuntime;
namespace SimpleCollectionView
{
@ -34,21 +34,21 @@ namespace SimpleCollectionView
};
}
public override int NumberOfSections (UICollectionView collectionView)
public override nint NumberOfSections (UICollectionView collectionView)
{
return 1;
}
public override int GetItemsCount (UICollectionView collectionView, int section)
public override nint GetItemsCount (UICollectionView collectionView, nint section)
{
return animals.Count;
}
public override UICollectionViewCell GetCell (UICollectionView collectionView, MonoTouch.Foundation.NSIndexPath indexPath)
public override UICollectionViewCell GetCell (UICollectionView collectionView, Foundation.NSIndexPath indexPath)
{
var animalCell = (AnimalCell)collectionView.DequeueReusableCell (animalCellId, indexPath);
var animal = animals [indexPath.Row];
var animal = animals [(int)indexPath.Row];
animalCell.Image = animal.Image;
@ -90,12 +90,12 @@ namespace SimpleCollectionView
return true;
}
public override bool CanPerformAction (UICollectionView collectionView, MonoTouch.ObjCRuntime.Selector action, NSIndexPath indexPath, NSObject sender)
public override bool CanPerformAction (UICollectionView collectionView, ObjCRuntime.Selector action, NSIndexPath indexPath, NSObject sender)
{
return true;
}
public override void PerformAction (UICollectionView collectionView, MonoTouch.ObjCRuntime.Selector action, NSIndexPath indexPath, NSObject sender)
public override void PerformAction (UICollectionView collectionView, ObjCRuntime.Selector action, NSIndexPath indexPath, NSObject sender)
{
Console.WriteLine ("code to perform action");
}
@ -144,7 +144,7 @@ namespace SimpleCollectionView
UIImageView imageView;
[Export ("initWithFrame:")]
public AnimalCell (System.Drawing.RectangleF frame) : base (frame)
public AnimalCell (CoreGraphics.CGRect frame) : base (frame)
{
BackgroundView = new UIView{BackgroundColor = UIColor.Orange};
@ -184,9 +184,9 @@ namespace SimpleCollectionView
}
[Export ("initWithFrame:")]
public Header (System.Drawing.RectangleF frame) : base (frame)
public Header (CoreGraphics.CGRect frame) : base (frame)
{
label = new UILabel (){Frame = new System.Drawing.RectangleF (0,0,300,50), BackgroundColor = UIColor.Yellow};
label = new UILabel (){Frame = new CoreGraphics.CGRect (0,0,300,50), BackgroundColor = UIColor.Yellow};
AddSubview (label);
}
}