SlideShare ist ein Scribd-Unternehmen logo
1 von 54
iOS for C# Developers
Miguel de Icaza – Xamarin Inc
@migueldeicaza
iOS Adoption
.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
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
Objective-C Action/Target
• Poor man’s C# delegate.
• In .NET this is mapped to a C# delegate
– Use methods
– Anonymous methods
– Lambdas
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
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
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
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)
THE BASICS
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
Complete app
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
Hierarchy
Screens
Windows
ViewControllers

Views or ViewControllers
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
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.
UIView
• Base class for all UI
Elements

BackgroundColor = UIColor.Red
UIView Subclasses
UIButton

Simple UIViews

UIPicker

Controls
UISlider
UIControl
UISwitch
UIImageView
UIStepper
UILabel

UIView

UITextField
UIProgressView
UITableView
UIScrollView

UITextView
UICollectionView

10,000 foot view, not comprehensive

ScrollViews
UIViews are General Containers
Can be arbitrarily nested
UIView methods:
AddSubview (UISubview)
RemoveFromSuperview ()
Unlike Gtk/Winforms:
Everything is a container
Can be Arbitrarily Nested
UIView’s
• Frame
– Superview coordinates
– RectangleF

• Bounds
– Size in UIView’s
coordinates

• Transform
– 2D Affine transformation

• Center
– Superview coordinates

X, Y = (20,10)
Center X, Y = (35,20)

W,H=(50,30)
2D Affine Transforms

Rotation

Translation

Shearing

Scaling
UIView’s
• Frame
– Superview coordinates
– RectangleF

• Bounds
– Size in UIView’s
coordinates

• Transform
– 2D Affine transformation

• Center
– Superview coordinates

45’ rotation over the
center
UIView Center+Affine Transforms
• Frame
– Superview coordinates
– RectangleF

• Bounds
– Size in UIView’s
coordinates

• Transform
– 2D Affine transformation

• Center
– Superview coordinates
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
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));
}
}
}
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)
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
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
Sample
Dynamics – new in iOS 7
• Introduces a physics engine into the UI
– Gravity
– Collision
– Attachment
– Snap
– Forces/Pushing
Gravity + Collision Detection
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
Manually Creating your UI
Using a UI Designer
UIViewControllers in UIKit
UIActivityViewController

Built-in UI

UICollectionViewController

Building Blocks
UINavigationViewController
UIPageViewController
UIViewController
UIReferenceLibraryViewController

UITabBarViewController
UITableViewController
UISplitVuewController

UIViewControllers in UIKit.
Built-in UI
UIActivityViewController

UIReferenceLibraryViewController
Other UIViewControllers
•

AddressBookUI

•

– ABNewPersonViewController
– ABPersonViewController
– ABUnknownPersonViewController

•

– MCBrowserViewController
– MCPeerPickerViewController

•
EventKitUI
– EKCalendarChooser
– EKEventViewController

MultipeerConnectivity

PassKit
– PKAddPassesViewController

•

QuickLook
– QLPreviewController

•

GLKit
– GLKViewController

•

•

Social/Twitter
– SLComposeViewController
– TWTweetComposeViewController

GameKit
– GKMatchmakerViewController

•

•

MediaPlayer
– MPMediaPickerController
– MPMoviePlayerViewController.

StoreKit
– SKStoreProductViewController
Some Examples
ABNewPersonViewController

EKEventViewController
Some Examples
TWTweetComposeViewController

MPMoviewPlayerViewController
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
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
UIControl
Common Controls
Strongly Typed Notifications
• NSNotificationCenter
– Application Message Bus
– Hub for posting messages
• “Keyboard will appear”
• “Font size changed”

• Strongly typed in C#
– Class.Notification.ObserveXXXX ()
Strongly Typed
THREE VIEWS TO MASTER
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
UITableView
• Most UI in iOS is a table
• Variable height
• External Data Source
– Request Section/Row
– Return UITableViewCell

• External Delegate
• Powerful
• And Cumbersome
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
MonoTouch.Dialog sample
• Sample program
• Mimics Sounds Settings
UICollectionView
• Arbitrary collections
• In any form you want
–
–
–
–

Table, Grid
Baseball diamond
Circle
Or anything you can
provide rules for
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

Weitere ähnliche Inhalte

Was ist angesagt?

Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mohammad Shaker
 
Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.
Mohammad Shaker
 

Was ist angesagt? (20)

Build 2017 - B8099 - What's new in Xamarin.Forms
Build 2017 - B8099 - What's new in Xamarin.FormsBuild 2017 - B8099 - What's new in Xamarin.Forms
Build 2017 - B8099 - What's new in Xamarin.Forms
 
Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017
 
Azure mobile services
Azure mobile servicesAzure mobile services
Azure mobile services
 
Connected Mobile Apps with Microsoft Azure
Connected Mobile Apps with Microsoft AzureConnected Mobile Apps with Microsoft Azure
Connected Mobile Apps with Microsoft Azure
 
Xamarin DevOps
Xamarin DevOpsXamarin DevOps
Xamarin DevOps
 
Build 2017 - P4115 - Go big! Optimizing your applications for large screen ex...
Build 2017 - P4115 - Go big! Optimizing your applications for large screen ex...Build 2017 - P4115 - Go big! Optimizing your applications for large screen ex...
Build 2017 - P4115 - Go big! Optimizing your applications for large screen ex...
 
Introduction to xamarin
Introduction to xamarinIntroduction to xamarin
Introduction to xamarin
 
Introduction to CocosSharp
Introduction to CocosSharpIntroduction to CocosSharp
Introduction to CocosSharp
 
Meteor Introduction - Ashish
Meteor Introduction - AshishMeteor Introduction - Ashish
Meteor Introduction - Ashish
 
Make your animations perform well - Anna Migas - Codemotion Rome 2017
Make your animations perform well - Anna Migas - Codemotion Rome 2017Make your animations perform well - Anna Migas - Codemotion Rome 2017
Make your animations perform well - Anna Migas - Codemotion Rome 2017
 
Building Games for iOS, macOS, and tvOS with Visual Studio and Azure
Building Games for iOS, macOS, and tvOS with Visual Studio and AzureBuilding Games for iOS, macOS, and tvOS with Visual Studio and Azure
Building Games for iOS, macOS, and tvOS with Visual Studio and Azure
 
Meteor js - TechPeaks Developers Meeting
Meteor js - TechPeaks Developers MeetingMeteor js - TechPeaks Developers Meeting
Meteor js - TechPeaks Developers Meeting
 
Intro to Meteor [Deprecated]
Intro to Meteor [Deprecated]Intro to Meteor [Deprecated]
Intro to Meteor [Deprecated]
 
Meteor Rails-2015
Meteor Rails-2015Meteor Rails-2015
Meteor Rails-2015
 
Meteor intro-2015
Meteor intro-2015Meteor intro-2015
Meteor intro-2015
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhone
 
Meteor.js for DOers
Meteor.js for DOersMeteor.js for DOers
Meteor.js for DOers
 
Highlights from the Xamarin Evolve 2016 conference
Highlights from the Xamarin Evolve 2016 conferenceHighlights from the Xamarin Evolve 2016 conference
Highlights from the Xamarin Evolve 2016 conference
 
Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.
 
Build 2017 - B8110 - Modernize WinForms and WPF apps with maximum code reuse,...
Build 2017 - B8110 - Modernize WinForms and WPF apps with maximum code reuse,...Build 2017 - B8110 - Modernize WinForms and WPF apps with maximum code reuse,...
Build 2017 - B8110 - Modernize WinForms and WPF apps with maximum code reuse,...
 

Ähnlich wie iOS for C# Developers - DevConnections Talk

iOS Development: What's New
iOS Development: What's NewiOS Development: What's New
iOS Development: What's New
NascentDigital
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
MugiiiReee
 

Ähnlich wie iOS for C# Developers - DevConnections Talk (20)

Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart Jfokus
 
Synapse india mobile apps update
Synapse india mobile apps updateSynapse india mobile apps update
Synapse india mobile apps update
 
Synapse india reviews on i phone and android os
Synapse india reviews on i phone and android osSynapse india reviews on i phone and android os
Synapse india reviews on i phone and android os
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
Xamarin.Mac Introduction
Xamarin.Mac IntroductionXamarin.Mac Introduction
Xamarin.Mac Introduction
 
Ios development 2
Ios development 2Ios development 2
Ios development 2
 
iOS Development: What's New
iOS Development: What's NewiOS Development: What's New
iOS Development: What's New
 
Diving Into Xamarin.Forms
Diving Into Xamarin.Forms Diving Into Xamarin.Forms
Diving Into Xamarin.Forms
 
Xamarin.iOS introduction
Xamarin.iOS introductionXamarin.iOS introduction
Xamarin.iOS introduction
 
Advance ui development and design
Advance ui  development and design Advance ui  development and design
Advance ui development and design
 
iOS (7) Workshop
iOS (7) WorkshopiOS (7) Workshop
iOS (7) Workshop
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 
Android by Swecha
Android by SwechaAndroid by Swecha
Android by Swecha
 
iOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIs
 
Android Workshop_1
Android Workshop_1Android Workshop_1
Android Workshop_1
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVC
 
Android App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structureAndroid App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structure
 
Tools and practices for rapid application development
Tools and practices for rapid application developmentTools and practices for rapid application development
Tools and practices for rapid application development
 
Code camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyCode camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una Daly
 
Getting Started with XCTest and XCUITest for iOS App Testing
Getting Started with XCTest and XCUITest for iOS App TestingGetting Started with XCTest and XCUITest for iOS App Testing
Getting Started with XCTest and XCUITest for iOS App Testing
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

iOS for C# Developers - DevConnections Talk

  • 1. iOS for C# Developers Miguel de Icaza – Xamarin Inc @migueldeicaza
  • 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.
  • 17. UIView • Base class for all UI Elements BackgroundColor = UIColor.Red
  • 19. UIViews are General Containers Can be arbitrarily nested UIView methods: AddSubview (UISubview) RemoveFromSuperview () Unlike Gtk/Winforms: Everything is a container
  • 21. UIView’s • Frame – Superview coordinates – RectangleF • Bounds – Size in UIView’s coordinates • Transform – 2D Affine transformation • Center – Superview coordinates X, Y = (20,10) Center X, Y = (35,20) W,H=(50,30)
  • 23. UIView’s • Frame – Superview coordinates – RectangleF • Bounds – Size in UIView’s coordinates • Transform – 2D Affine transformation • Center – Superview coordinates 45’ rotation over the center
  • 24. UIView Center+Affine Transforms • Frame – Superview coordinates – RectangleF • Bounds – Size in UIView’s coordinates • Transform – 2D Affine transformation • Center – Superview coordinates
  • 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
  • 31. Dynamics – new in iOS 7 • Introduces a physics engine into the UI – Gravity – Collision – Attachment – Snap – Forces/Pushing
  • 32. Gravity + Collision Detection
  • 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
  • 35. Using a UI Designer
  • 36. UIViewControllers in UIKit UIActivityViewController Built-in UI UICollectionViewController Building Blocks UINavigationViewController UIPageViewController UIViewController UIReferenceLibraryViewController UITabBarViewController UITableViewController UISplitVuewController UIViewControllers in UIKit.
  • 38. Other UIViewControllers • AddressBookUI • – ABNewPersonViewController – ABPersonViewController – ABUnknownPersonViewController • – MCBrowserViewController – MCPeerPickerViewController • EventKitUI – EKCalendarChooser – EKEventViewController MultipeerConnectivity PassKit – PKAddPassesViewController • QuickLook – QLPreviewController • GLKit – GLKViewController • • Social/Twitter – SLComposeViewController – TWTweetComposeViewController GameKit – GKMatchmakerViewController • • MediaPlayer – MPMediaPickerController – MPMoviePlayerViewController. StoreKit – SKStoreProductViewController
  • 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
  • 45. Strongly Typed Notifications • NSNotificationCenter – Application Message Bus – Hub for posting messages • “Keyboard will appear” • “Font size changed” • Strongly typed in C# – Class.Notification.ObserveXXXX ()
  • 47. THREE VIEWS TO MASTER
  • 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
  • 51. MonoTouch.Dialog sample • Sample program • Mimics Sounds Settings
  • 52.
  • 53. UICollectionView • Arbitrary collections • In any form you want – – – – Table, Grid Baseball diamond Circle Or anything you can provide rules for
  • 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

  1. Two state of the art platformsiOS only mainstream UI toolkit designed for the GPUCover the principles of iOS DevelopmentThe UIKit Framework