зеркало из https://github.com/xamarin/ios-samples.git
Add KeyValueObserver sample
This commit is contained in:
Родитель
1a27d06c5f
Коммит
a020e76247
|
@ -0,0 +1,78 @@
|
|||
//
|
||||
// kvo: Shows how to observe property changes on an object
|
||||
//
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
using MonoTouch.Foundation;
|
||||
using MonoTouch.UIKit;
|
||||
|
||||
namespace kvo
|
||||
{
|
||||
[Register ("AppDelegate")]
|
||||
public partial class AppDelegate : UIApplicationDelegate
|
||||
{
|
||||
UINavigationController topController;
|
||||
UIWindow window;
|
||||
UILabel label;
|
||||
|
||||
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
|
||||
{
|
||||
topController = new UINavigationController ();
|
||||
topController.View.BackgroundColor = UIColor.Gray;
|
||||
|
||||
label = new UILabel (ComputeLabelRect ()) {
|
||||
Text = "Rotate the phone to observe the `bounds' change",
|
||||
LineBreakMode = UILineBreakMode.WordWrap,
|
||||
Lines = 20,
|
||||
BackgroundColor = UIColor.LightGray
|
||||
};
|
||||
topController.View.AddSubview (label);
|
||||
|
||||
window = new UIWindow (UIScreen.MainScreen.Bounds) {
|
||||
RootViewController = topController
|
||||
};
|
||||
window.MakeKeyAndVisible ();
|
||||
|
||||
//
|
||||
// Observe changes to the topController's View property, in this case, we want to
|
||||
// observe changes to the "bounds" property (this is the name of the Objective-C
|
||||
// property).
|
||||
//
|
||||
// The changes observed are delivered to "this", which is expected to override
|
||||
// the "ObserveValue" method.
|
||||
//
|
||||
topController.View.AddObserver (observer: this,
|
||||
keyPath: new NSString ("bounds"),
|
||||
options: NSKeyValueObservingOptions.New,
|
||||
context: IntPtr.Zero);
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// Override the ObserveValue method on the class that you designate as the observer
|
||||
//
|
||||
public override void ObserveValue (NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
|
||||
{
|
||||
var str = String.Format ("The {0} property on {1}, the change is: {2}", keyPath, ofObject, change.Description);
|
||||
Console.WriteLine (str);
|
||||
label.Text = str;
|
||||
|
||||
label.Frame = ComputeLabelRect ();
|
||||
}
|
||||
|
||||
RectangleF ComputeLabelRect ()
|
||||
{
|
||||
var rect = topController.View.Bounds;
|
||||
rect.Inflate (-20, -80);
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
static void Main (string[] args)
|
||||
{
|
||||
UIApplication.Main (args, null, "AppDelegate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?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>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<SampleMetadata>
|
||||
<ID>3E74DD9C-7B83-4A40-A746-B73C373D84A1</ID>
|
||||
<IsFullApplication>true</IsFullApplication>
|
||||
<Level>Intermediate</Level>
|
||||
<Tags>Fundamentals</Tags>
|
||||
</SampleMetadata>
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 93 KiB |
|
@ -0,0 +1,71 @@
|
|||
<?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>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{AAC33071-D84F-4543-B45F-440CC9BD560E}</ProjectGuid>
|
||||
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>kvo</RootNamespace>
|
||||
<AssemblyName>kvo</AssemblyName>
|
||||
</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>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</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>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\iPhone\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="monotouch" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Info.plist" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AppDelegate.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.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}") = "kvo", "kvo.csproj", "{AAC33071-D84F-4543-B45F-440CC9BD560E}"
|
||||
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
|
||||
{AAC33071-D84F-4543-B45F-440CC9BD560E}.Debug|iPhone.ActiveCfg = Debug|iPhone
|
||||
{AAC33071-D84F-4543-B45F-440CC9BD560E}.Debug|iPhone.Build.0 = Debug|iPhone
|
||||
{AAC33071-D84F-4543-B45F-440CC9BD560E}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
|
||||
{AAC33071-D84F-4543-B45F-440CC9BD560E}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
|
||||
{AAC33071-D84F-4543-B45F-440CC9BD560E}.Release|iPhone.ActiveCfg = Release|iPhone
|
||||
{AAC33071-D84F-4543-B45F-440CC9BD560E}.Release|iPhone.Build.0 = Release|iPhone
|
||||
{AAC33071-D84F-4543-B45F-440CC9BD560E}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
|
||||
{AAC33071-D84F-4543-B45F-440CC9BD560E}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = kvo.csproj
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Загрузка…
Ссылка в новой задаче