зеркало из https://github.com/xamarin/ios-samples.git
FrogScroller sample ported to 64-bits
This commit is contained in:
Родитель
fefb4485fe
Коммит
4fc7b7d302
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
|
||||
using MonoTouch.Foundation;
|
||||
using MonoTouch.UIKit;
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace FrogScroller
|
||||
{
|
||||
|
|
|
@ -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>
|
||||
|
@ -25,6 +25,7 @@
|
|||
<MtouchProfiling>True</MtouchProfiling>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchArch>ARMv7</MtouchArch>
|
||||
<MtouchExtraArgs>--registrar:static --nofastsim --override-abi x86_64</MtouchExtraArgs>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
|
||||
<DebugType>none</DebugType>
|
||||
|
@ -88,7 +89,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" />
|
||||
|
@ -757,4 +760,4 @@
|
|||
<ItemGroup>
|
||||
<ITunesArtwork Include="Resources\iTunesArtwork.png" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#define TILE_IMAGES
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using CoreGraphics;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
using MonoTouch.Foundation;
|
||||
using MonoTouch.UIKit;
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace FrogScroller
|
||||
{
|
||||
|
@ -20,20 +20,20 @@ namespace FrogScroller
|
|||
|
||||
public class ImageScrollView : UIScrollView
|
||||
{
|
||||
SizeF _imageSize;
|
||||
CGSize _imageSize;
|
||||
UIImageView zoomView; // if tiling this contains a very low-res placeholder image. otherwise it contains the full image.
|
||||
#if TILE_IMAGES
|
||||
TilingView tilingView;
|
||||
#endif
|
||||
PointF _pointToCenterAfterResize;
|
||||
float _scaleToRestoreAfterResize;
|
||||
CGPoint _pointToCenterAfterResize;
|
||||
nfloat _scaleToRestoreAfterResize;
|
||||
int _index;
|
||||
|
||||
public ImageScrollView () : base ()
|
||||
{
|
||||
}
|
||||
|
||||
public ImageScrollView (RectangleF frame) : base (frame)
|
||||
public ImageScrollView (CGRect frame) : base (frame)
|
||||
{
|
||||
ShowsVerticalScrollIndicator = false;
|
||||
ShowsHorizontalScrollIndicator = false;
|
||||
|
@ -77,7 +77,7 @@ namespace FrogScroller
|
|||
zoomView.Frame = frameToCenter;
|
||||
}
|
||||
|
||||
public override RectangleF Frame {
|
||||
public override CGRect Frame {
|
||||
get {
|
||||
return base.Frame;
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ namespace FrogScroller
|
|||
|
||||
// - Configure scrollView to display new image (tiled or not)
|
||||
#if TILE_IMAGES
|
||||
public void DisplayTiledImageNamed (string imageName, SizeF image_Size)
|
||||
public void DisplayTiledImageNamed (string imageName, CGSize image_Size)
|
||||
{
|
||||
//clear views for the previous image
|
||||
if (zoomView != null) {
|
||||
|
@ -106,7 +106,7 @@ namespace FrogScroller
|
|||
this.ZoomScale = 1.0f;
|
||||
|
||||
//make views to display the new image
|
||||
zoomView = new UIImageView (new RectangleF (PointF.Empty, image_Size)) {
|
||||
zoomView = new UIImageView (new CGRect (CGPoint.Empty, image_Size)) {
|
||||
Image = PlaceholderImageNamed (imageName)
|
||||
};
|
||||
|
||||
|
@ -135,7 +135,7 @@ namespace FrogScroller
|
|||
}
|
||||
#endif
|
||||
|
||||
public void ConfigureForImageSize (SizeF imageSize)
|
||||
public void ConfigureForImageSize (CGSize imageSize)
|
||||
{
|
||||
_imageSize = imageSize;
|
||||
ContentSize = imageSize;
|
||||
|
@ -145,19 +145,19 @@ namespace FrogScroller
|
|||
|
||||
public void SetMaxMinZoomScalesForCurrentBounds ()
|
||||
{
|
||||
SizeF boundsSize = Bounds.Size;
|
||||
CGSize boundsSize = Bounds.Size;
|
||||
|
||||
//calculate min/max zoomscale
|
||||
float xScale = boundsSize.Width / _imageSize.Width; //scale needed to perfectly fit the image width-wise
|
||||
float yScale = boundsSize.Height / _imageSize.Height; //scale needed to perfectly fit the image height-wise
|
||||
nfloat xScale = boundsSize.Width / _imageSize.Width; //scale needed to perfectly fit the image width-wise
|
||||
nfloat yScale = boundsSize.Height / _imageSize.Height; //scale needed to perfectly fit the image height-wise
|
||||
|
||||
//fill width if the image and phone are both portrait or both landscape; otherwise take smaller scale
|
||||
bool imagePortrait = _imageSize.Height > _imageSize.Width;
|
||||
bool phonePortrait = boundsSize.Height > boundsSize.Width;
|
||||
float minScale = (imagePortrait == phonePortrait ? xScale : Math.Min (xScale, yScale));
|
||||
nfloat minScale = (imagePortrait == phonePortrait ? xScale : (nfloat)Math.Min (xScale, yScale));
|
||||
|
||||
//on high resolution screens we have double the pixel density, so we will be seeing every pixel if we limit the maximum zoom scale to 0.5
|
||||
float maxScale = 1.0f / UIScreen.MainScreen.Scale;
|
||||
nfloat maxScale = 1.0f / UIScreen.MainScreen.Scale;
|
||||
|
||||
if (minScale > maxScale) {
|
||||
minScale = maxScale;
|
||||
|
@ -172,7 +172,7 @@ namespace FrogScroller
|
|||
// Rotation support
|
||||
public void PrepareToResize ()
|
||||
{
|
||||
var boundsCenter = new PointF (Bounds.Width / 2, Bounds.Height / 2);
|
||||
var boundsCenter = new CGPoint (Bounds.Width / 2, Bounds.Height / 2);
|
||||
_pointToCenterAfterResize = this.ConvertPointToView (boundsCenter, zoomView);
|
||||
_scaleToRestoreAfterResize = this.ZoomScale;
|
||||
// If we're at the minimum zoom scale, preserve that by returning 0, which will be converted to the minimum
|
||||
|
@ -186,31 +186,31 @@ namespace FrogScroller
|
|||
SetMaxMinZoomScalesForCurrentBounds ();
|
||||
|
||||
//Step 1: restore zoom scale, first making sure it is within the allowable range;
|
||||
ZoomScale = Math.Min (MaximumZoomScale, Math.Max (this.MinimumZoomScale, _scaleToRestoreAfterResize));
|
||||
ZoomScale = (nfloat)Math.Min (MaximumZoomScale, Math.Max (this.MinimumZoomScale, _scaleToRestoreAfterResize));
|
||||
|
||||
// Step 2: restore center point, first making sure it is within the allowable range.
|
||||
// 2a: convert our desired center point back to our own coordinate space
|
||||
var boundsCenter = this.ConvertPointFromView (_pointToCenterAfterResize, zoomView);
|
||||
// 2b: calculate the content offset that would yield that center point
|
||||
PointF offset = new PointF (boundsCenter.X - this.Bounds.Size.Width / 2.0f, boundsCenter.Y - this.Bounds.Size.Height / 2.0f);
|
||||
CGPoint offset = new CGPoint (boundsCenter.X - this.Bounds.Size.Width / 2.0f, boundsCenter.Y - this.Bounds.Size.Height / 2.0f);
|
||||
// 2c: restore offset, adjusted to be within the allowable range
|
||||
PointF maxOffset = MaximumContentOffset ();
|
||||
PointF minOffset = MinimumContentOffset ();
|
||||
offset.X = Math.Max (minOffset.X, Math.Min (maxOffset.X, offset.X));
|
||||
offset.Y = Math.Max (minOffset.Y, Math.Min (maxOffset.Y, offset.Y));
|
||||
CGPoint maxOffset = MaximumContentOffset ();
|
||||
CGPoint minOffset = MinimumContentOffset ();
|
||||
offset.X = (nfloat)Math.Max (minOffset.X, Math.Min (maxOffset.X, offset.X));
|
||||
offset.Y = (nfloat)Math.Max (minOffset.Y, Math.Min (maxOffset.Y, offset.Y));
|
||||
this.ContentOffset = offset;
|
||||
}
|
||||
|
||||
public PointF MaximumContentOffset ()
|
||||
public CGPoint MaximumContentOffset ()
|
||||
{
|
||||
SizeF contentSize = ContentSize;
|
||||
SizeF boundsSize = Bounds.Size;
|
||||
return new PointF (contentSize.Width - boundsSize.Width, contentSize.Height - boundsSize.Height);
|
||||
CGSize contentSize = ContentSize;
|
||||
CGSize boundsSize = Bounds.Size;
|
||||
return new CGPoint (contentSize.Width - boundsSize.Width, contentSize.Height - boundsSize.Height);
|
||||
}
|
||||
|
||||
public PointF MinimumContentOffset ()
|
||||
public CGPoint MinimumContentOffset ()
|
||||
{
|
||||
return PointF.Empty;
|
||||
return CGPoint.Empty;
|
||||
}
|
||||
|
||||
static List<ImageDetails> data;
|
||||
|
@ -252,10 +252,10 @@ namespace FrogScroller
|
|||
return _name [index].Name;
|
||||
}
|
||||
|
||||
public static SizeF ImageSizeAtIndex (int index)
|
||||
public static CGSize ImageSizeAtIndex (int index)
|
||||
{
|
||||
List<ImageDetails> _name = ImageData ();
|
||||
return new SizeF (_name [index].Width, _name [index].Height);
|
||||
return new CGSize (_name [index].Width, _name [index].Height);
|
||||
}
|
||||
|
||||
public static UIImage PlaceholderImageNamed (string name)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
|
||||
using MonoTouch.Foundation;
|
||||
using MonoTouch.UIKit;
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace FrogScroller
|
||||
{
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using MonoTouch.CoreAnimation;
|
||||
using MonoTouch.CoreGraphics;
|
||||
using MonoTouch.Foundation;
|
||||
using MonoTouch.ObjCRuntime;
|
||||
using MonoTouch.UIKit;
|
||||
using CoreGraphics;
|
||||
using CoreAnimation;
|
||||
|
||||
using Foundation;
|
||||
using ObjCRuntime;
|
||||
using UIKit;
|
||||
|
||||
namespace FrogScroller
|
||||
{
|
||||
|
@ -18,8 +18,8 @@ namespace FrogScroller
|
|||
|
||||
string ImageName { get; set; }
|
||||
|
||||
public TilingView (string name, SizeF size) :
|
||||
base (new RectangleF (PointF.Empty, size))
|
||||
public TilingView (string name, CGSize size) :
|
||||
base (new CGRect (CGPoint.Empty, size))
|
||||
{
|
||||
ImageName = name;
|
||||
var tiledLayer = (CATiledLayer)this.Layer;
|
||||
|
@ -29,13 +29,13 @@ namespace FrogScroller
|
|||
// tiling view's contentScaleFactor at 1.0. UIKit will try to set it back to 2.0 on retina displays, which is the
|
||||
// right call in most cases, but since we're backed by a CATiledLayer it will actually cause us to load the
|
||||
// wrong sized tiles.
|
||||
public override float ContentScaleFactor {
|
||||
public override nfloat ContentScaleFactor {
|
||||
set {
|
||||
base.ContentScaleFactor = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw (RectangleF rect)
|
||||
public override void Draw (CGRect rect)
|
||||
{
|
||||
using (var context = UIGraphics.GetCurrentContext ()) {
|
||||
|
||||
|
@ -67,7 +67,7 @@ namespace FrogScroller
|
|||
for (int col = firstCol; col <= lastCol; col++) {
|
||||
|
||||
UIImage tile = TileForScale (scale, row, col);
|
||||
var tileRect = new RectangleF (tileSize.Width * col, tileSize.Height * row, tileSize.Width, tileSize.Height);
|
||||
var tileRect = new CGRect (tileSize.Width * col, tileSize.Height * row, tileSize.Width, tileSize.Height);
|
||||
// if the tile would stick outside of our bounds, we need to truncate it so as to avoid
|
||||
// stretching out the partial tiles at the right and bottom edges
|
||||
tileRect.Intersect (this.Bounds);
|
||||
|
@ -77,7 +77,7 @@ namespace FrogScroller
|
|||
}
|
||||
}
|
||||
|
||||
public UIImage TileForScale (float scale, int row, int col)
|
||||
public UIImage TileForScale (nfloat scale, nint row, nint col)
|
||||
{
|
||||
// we use "FromFile" instead of "FromBundle" here because we don't want UIImage to cache our tiles
|
||||
string path = String.Format ("/Image/ImageTiles/{0}_{1}_{2}_{3}.png", ImageName, (int)(scale * 1000), (int)col, (int)row);
|
||||
|
|
Загрузка…
Ссылка в новой задаче