Added image view recipe sample code

This commit is contained in:
Nathan Castle 2015-06-19 14:21:07 -04:00
Родитель 48d60c32f0
Коммит 47e1316b2c
21 изменённых файлов: 521 добавлений и 0 удалений

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

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
namespace MapView {
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate {
// class-level declarations
UIWindow window;
UINavigationController navigationController;
UIViewController viewController;
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// create a new window instance based on the screen size
window = new UIWindow (UIScreen.MainScreen.Bounds);
viewController = new ImageViewController();
navigationController = new UINavigationController();
navigationController.PushViewController (viewController, false);
// If you have defined a view, add it here:
window.AddSubview (navigationController.View);
// make the window visible
window.MakeKeyAndVisible ();
return true;
}
}
}

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

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9785D147-C90E-47FD-A1A0-CBD233E708BB}</ProjectGuid>
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>MapView</RootNamespace>
<AssemblyName>MapView</AssemblyName>
<TargetFrameworkIdentifier>Xamarin.iOS</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchDebug>true</MtouchDebug>
<MtouchProfiling>true</MtouchProfiling>
<MtouchLink>None</MtouchLink>
<MtouchI18n>
</MtouchI18n>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchLink>None</MtouchLink>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchDebug>true</MtouchDebug>
<MtouchProfiling>true</MtouchProfiling>
<IpaPackageName>
</IpaPackageName>
<MtouchArch>ARMv7</MtouchArch>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchArch>ARMv7, ARM64</MtouchArch>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="ImageViewController.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Spinning Circle_1.png" />
<Content Include="Spinning Circle_2.png" />
<Content Include="Spinning Circle_3.png" />
<Content Include="Spinning Circle_4.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
<ImageAsset Include="Resources\Images.xcassets\LaunchImage.launchimage\Contents.json" />
</ItemGroup>
</Project>

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

@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageView", "ImageView.csproj", "{9785D147-C90E-47FD-A1A0-CBD233E708BB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|iPhoneSimulator = Debug|iPhoneSimulator
Release|iPhoneSimulator = Release|iPhoneSimulator
Debug|iPhone = Debug|iPhone
Release|iPhone = Release|iPhone
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Debug|iPhone.ActiveCfg = Debug|iPhone
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Debug|iPhone.Build.0 = Debug|iPhone
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Release|iPhone.ActiveCfg = Release|iPhone
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Release|iPhone.Build.0 = Release|iPhone
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = ImageView.csproj
EndGlobalSection
EndGlobal

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

@ -0,0 +1,31 @@
using CoreGraphics;
using UIKit;
namespace MapView {
public class ImageViewController : UIViewController {
UIImageView animatedCircleImage;
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
Title = "Animated ImageView";
View.BackgroundColor = UIColor.White;
// an animating image
animatedCircleImage = new UIImageView();
animatedCircleImage.AnimationImages = new UIImage[] {
UIImage.FromBundle ("Spinning Circle_1.png")
, UIImage.FromBundle ("Spinning Circle_2.png")
, UIImage.FromBundle ("Spinning Circle_3.png")
, UIImage.FromBundle ("Spinning Circle_4.png")
} ;
animatedCircleImage.AnimationRepeatCount = 0;
animatedCircleImage.AnimationDuration = .5;
animatedCircleImage.Frame = new CGRect(110, 80, 100, 100);
View.AddSubview(animatedCircleImage);
animatedCircleImage.StartAnimating ();
}
}
}

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

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.xamarin.recipe.imageview</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>8.3</string>
<key>XSLaunchImageAssets</key>
<string>Resources/Images.xcassets/LaunchImage.launchimage</string>
</dict>
</plist>

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

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
namespace MapView {
public class Application {
// This is the main entry point of the application.
static void Main (string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main (args, null, "AppDelegate");
}
}
}

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

@ -0,0 +1,7 @@
{
"images": [],
"info": {
"version": 1,
"author": "xcode"
}
}

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.7 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.7 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.7 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.7 KiB

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

@ -0,0 +1,48 @@
id:{2690BBD5-0ACB-DDA3-7808-CBB0094165F8}
title:Animate an ImageView
brief:This recipe shows how to animate a UIImageView with an array of image frames
samplecode:[Animate_an_ImageView](https://github.com/xamarin/recipes/tree/master/ios/standard_controls/image_view/animate_an_imageview)
article:[Load an Image](/recipes/ios/standard_controls/image_view/load_an_image)
sdk:[UIImageView Class Reference](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/Reference/Reference.html)
<a name="Recipe" class="injected"></a>
# Recipe
To display an image:
- Add all the image frames to your Xamarin.iOS project and ensure the Build Action is set to Content.
- Create a UIImageView:
```
var imageView = new UIImageView ();
animatedCircleImage.Frame = new RectangleF(110, 20, 100, 100);
```
- Create an array of the image frames and assign it to AnimationImages:
```
animatedCircleImage.AnimationImages = new UIImage[] {
UIImage.FromBundle ("Spinning Circle_1.png")
, UIImage.FromBundle ("Spinning Circle_2.png")
, UIImage.FromBundle ("Spinning Circle_3.png")
, UIImage.FromBundle ("Spinning Circle_4.png")
};
```
- Set the animation properties and start animating:
```
animatedCircleImage.AnimationRepeatCount = 0;
animatedCircleImage.AnimationDuration = .5;
animatedCircleImage.StartAnimating();
```
The sample code shows the circle animating (difficult to demonstrate in a
screenshot):
[ ![](Images/ImageViewAnim1.png)](Images/ImageViewAnim1.png)

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

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
namespace MapView {
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate {
// class-level declarations
UIWindow window;
UINavigationController navigationController;
UIViewController viewController;
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// create a new window instance based on the screen size
window = new UIWindow (UIScreen.MainScreen.Bounds);
viewController = new ImageViewController();
navigationController = new UINavigationController();
navigationController.PushViewController (viewController, false);
// If you have defined a view, add it here:
window.AddSubview (navigationController.View);
// make the window visible
window.MakeKeyAndVisible ();
return true;
}
}
}

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

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9785D147-C90E-47FD-A1A0-CBD233E708BB}</ProjectGuid>
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>MapView</RootNamespace>
<AssemblyName>MapView</AssemblyName>
<TargetFrameworkIdentifier>Xamarin.iOS</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchDebug>true</MtouchDebug>
<MtouchProfiling>true</MtouchProfiling>
<MtouchLink>None</MtouchLink>
<MtouchI18n>
</MtouchI18n>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchLink>None</MtouchLink>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchDebug>true</MtouchDebug>
<MtouchProfiling>true</MtouchProfiling>
<IpaPackageName>
</IpaPackageName>
<MtouchArch>ARMv7</MtouchArch>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchArch>ARMv7, ARM64</MtouchArch>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="ImageViewController.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="MonkeySFO.png" />
</ItemGroup>
<ItemGroup>
<ImageAsset Include="Resources\Images.xcassets\LaunchImage.launchimage\Contents.json" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
</Project>

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

@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageView", "ImageView.csproj", "{9785D147-C90E-47FD-A1A0-CBD233E708BB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|iPhoneSimulator = Debug|iPhoneSimulator
Release|iPhoneSimulator = Release|iPhoneSimulator
Debug|iPhone = Debug|iPhone
Release|iPhone = Release|iPhone
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Debug|iPhone.ActiveCfg = Debug|iPhone
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Debug|iPhone.Build.0 = Debug|iPhone
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Release|iPhone.ActiveCfg = Release|iPhone
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Release|iPhone.Build.0 = Release|iPhone
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{9785D147-C90E-47FD-A1A0-CBD233E708BB}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = ImageView.csproj
EndGlobalSection
EndGlobal

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

@ -0,0 +1,22 @@
using CoreGraphics;
using UIKit;
namespace MapView {
public class ImageViewController : UIViewController {
UIImageView imageView;
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
Title = "ImageView";
View.BackgroundColor = UIColor.White;
// a simple image
imageView = new UIImageView (UIImage.FromBundle ("MonkeySFO.png")); // Build Action:Content
imageView.Frame = new CGRect (10, 80, imageView.Image.CGImage.Width, imageView.Image.CGImage.Height);
View.AddSubview (imageView);
}
}
}

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

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.xamarin.recipe.mapview</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>8.3</string>
<key>XSLaunchImageAssets</key>
<string>Resources/Images.xcassets/LaunchImage.launchimage</string>
</dict>
</plist>

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

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
namespace MapView {
public class Application {
// This is the main entry point of the application.
static void Main (string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main (args, null, "AppDelegate");
}
}
}

Двоичные данные
ios/standard_controls/image_view/load_an_image/MonkeySFO.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 188 KiB

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

@ -0,0 +1,7 @@
{
"images": [],
"info": {
"version": 1,
"author": "xcode"
}
}

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

@ -0,0 +1,3 @@
This is the sample code for the load an image iOS recipe on Xamarin.com.
[See the recipe](http://developer.xamarin.com/recipes/ios/standard_controls/image_view/load_an_image/)