3. .NET Event Idiom
Objects raising a number
of events
MyControl
F.Clicked += EventHandler
OnEnter
OnLeave
Storage for
properties/events:
• either in object
• Or uses bags, like
DependencyProperties
Clicked
Background
Font
4. Objective-C Delegate Idiom
Objects use a peer object
to post notifications
MyControl
Delegate
Background
f.Delegate = new myDelegate ();
Must implement methods
in MyDelegate
Font
MyControlDelegate
OnEnter
OnLeave
Clicked
5. Objective-C Action/Target
• Poor man’s C# delegate.
• In .NET this is mapped to a C# delegate
– Use methods
– Anonymous methods
– Lambdas
6. C# on iOS
• All the features you come to expect from C#
• IDEs:
– Visual Studio on Windows
– Xamarin Studio on Mac
• Think of iOS as another platform to target
– Just like you ASP.NET or WPF are
– Same level of code sharing
7. APIs for C# Developers on iOS
• .NET’s Base Class Libraries
– mscorlib, System, System.Core, System.Data
– System.Web.Services
– etc
• Native iOS APIs surfaced as C# classes
– Mapped with some artistic liberties:
– Follow .NET’s Framework Design Guidelines
8. iOS APIs Surfaced to .NET
• Objective-C to C# bridge
– Special runtime support for these
– Integrates the Object Systems
• Object Oriented C Code
– Manually mapped to C# classes
• Mostly CoreFoundation derived types
• Regular C code
– Mapped to C# classes as well
9. iOS APIs for .NET
• iOS APIs are weakly typed
– Similar to .NET 1.0 code
• C# bindings are strongly typed
– Helps explore the API
– Let the IDE help you write your code
• Async-ified (same rules as .NET async)
11. Starting Up
• C# Main () method
– Call UIApplication.Main
– Pass the name of your application delegate class
• System creates UIApplication class
– Instantiates your UIApplicationDelegate
• UIApplicationDelegate methods invoked
– FinishedLaunching performs UI setup
13. UIApplicationDelegate
• How the operating system talks to your app
• Mostly deals with state:
–
–
–
–
–
Starting up (fresh, openUrl request)
Suspending
Resuming
Respond to notifications
Background downloads
• Also: data security, UI orientation
15. UIScreen
• Represents a screen available in your device
• UIScreen.MainScreen is the main screen
– Same as UIScreen.Screens [0]
• Other screens used for external connectors
16. UIWindows
• Developers use one (system does others)
– Routes events
– Sets the Root View Controller
• UIWindow.RootViewController
– Must be set by the end of running your
FinishedLaunching method.
19. UIViews are General Containers
Can be arbitrarily nested
UIView methods:
AddSubview (UISubview)
RemoveFromSuperview ()
Unlike Gtk/Winforms:
Everything is a container
25. Custom UIView - Rendering
• Override Draw (RectangleF region) method
– Must paint the entire requested region
• Obtain the UIGraphics’ current draw context
• CGContext: Immediate graphics API
– Similar to System.Drawing on Windows.Forms
– Not retained, like Silverlight
26. Sample
public override void Draw (RectangleF rect)
{
using (CGContext context = UIGraphics.GetCurrentContext ()) {
// turn on anti-aliasing
context.SetAllowsAntialiasing (true);
// loop through each spot and draw it
foreach (Spot s in touchSpots) {
context.SetFillColor (s.Red, s.Green, s.Blue, s.Alpha);
context.FillEllipseInRect (new RectangleF (s.Point,size));
}
}
}
27. Custom UIViews – Touch Handling
• Configure properties:
– UserInteractionEnabled, MultipleTouchEnabled
• Override:
TouchesBegan:
– User touched the UI
TouchesMoved
– Updated locations
TouchesEnded
– User lifted fingers
TouchesCancelled
– System cancelled (for example, incoming call)
28. Animation
• UIKit is powered by an animation framework
– Details, beyond the scope of today’s talk
• Certain properties can be animated:
– Frame, Bounds, Center, Transform
– Alpha, BackgroundColor, ContentStretch
• Very little setup needed
29. Animation + Async
• UIView.Animate methods
• Use AnimateNotifyAsync family of methods
– Duration
– Lambda to update visual properties
– Options controlling animation
• Await on the call
– Will resume execution after animation completes
33. UIViewController
• Typically a full screen of content
• Host for your views
– In charge of layout
– Orientation changes
– Provides event routing for your views
• Some can host other UIViewControllers
– “UIViewController Containment”
• UIViewController.View property is the root UIView
41. UIViewControllers and Storyboards
• Name your class in the designer
– Will be reflected in your code
• Only after ViewDidLoad () are objects created
– Any references to other views or controllers
– Wont be valid until after this method is called
42. Presenting View Controllers
• Given a current UIViewController, call:
– PresentViewController
– PresentViewControllerAsync
• Modality of controller:
– bool ModalViewController {get;set}
• You can build your own visual transition
– And control every step of it
48. UIScrollView
• Where the magic originates
• Powerful control that handles scrolling
– Pagination, scrolling, smooth motion
• Must see: Series of WWDC talks on it
– Every possible trick and hack
49. UITableView
• Most UI in iOS is a table
• Variable height
• External Data Source
– Request Section/Row
– Return UITableViewCell
• External Delegate
• Powerful
• And Cumbersome
50. MonoTouch.Dialog – UITableView
made easy
• Switches the model
– From callback to fetch data (very scalable)
– To dump all data into view (easy, not scalable)
• Elements:
– Provide cell-specific style renderers
54. More Resources
Wallace McClure’s talk
Mechanics of it - Right after this one
Islander IE
• http://developer.apple.com/ios
•
Apple’s site
• http://docs.xamarin.com/ios
– Docs, tutorials on C# and iOS
• http://planet.xamarin.com
– Technical Blogs from the community
Hinweis der Redaktion
Two state of the art platformsiOS only mainstream UI toolkit designed for the GPUCover the principles of iOS DevelopmentThe UIKit Framework