get the most out of ios 11 with visual studio tools for xamarin
TRANSCRIPT
aka.ms/xamarin/ios11-todo11
// UINavigationControllerNavigationBar.PrefersLargeTitles = true;
// UIViewController (second one in stack)NavigationItem.LargeTitleDisplayMode = UINavigationItemLargeTitleDisplayMode.Never;
// AppDelegateUINavigationBar.Appearance.LargeTitleTextAttributes = new UIStringAttributes{
ForegroundColor = UIColor.FromRGB(0x5A, 0x86, 0x22), // 5A8622 dark-green};
new
SafeAreaLayoutGuide
MarginLayoutGuide
Safe Area var safeGuide = View.SafeAreaLayoutGuide;
NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] {CloseButton.TrailingAnchor.ConstraintEqualTo(safeGuide.TrailingAnchor, -23),CloseButton.BottomAnchor.ConstraintEqualTo(safeGuide.BottomAnchor, -13),CloseButton.WidthAnchor.ConstraintEqualTo(60),CloseButton.HeightAnchor.ConstraintEqualTo(60)
});
-23
-13
var safeGuide = View.SafeAreaLayoutGuide;
NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] {CloseButton.TrailingAnchor.ConstraintEqualTo(safeGuide.TrailingAnchor, -23),CloseButton.BottomAnchor.ConstraintEqualTo(safeGuide.BottomAnchor, -13),CloseButton.WidthAnchor.ConstraintEqualTo(60),CloseButton.HeightAnchor.ConstraintEqualTo(60)
});
NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] { CameraButton.TrailingAnchor.ConstraintEqualTo(CloseButton.LeadingAnchor, -23), CameraButton.BottomAnchor.ConstraintEqualTo(safeGuide.BottomAnchor, -13), CameraButton.WidthAnchor.ConstraintEqualTo(60), CameraButton.HeightAnchor.ConstraintEqualTo(60)
});
Safe Area
-23
-13
-13
var marginGuide = View.LayoutMarginsGuide;
NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] { ClassificationLabel.LeadingAnchor.ConstraintEqualTo(marginGuide.LeadingAnchor), ClassificationLabel.TrailingAnchor.ConstraintEqualTo(marginGuide.TrailingAnchor), ClassificationLabel.BottomAnchor.ConstraintEqualTo(CloseButton.TopAnchor, -13), ClassificationLabel.HeightAnchor.ConstraintEqualTo(120)
});
MarginMargin
var context = new LAContext();
// Face ID or Touch IDcontext.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out var err1)
context.BiometryType == LABiometryType.TouchId ? "Touch ID" : "Face ID"
// PIN/Passwordcontext.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, out var err2)
var context = new LAContext();
// Face ID or Touch IDcontext.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out var err1)
context.BiometryType == LABiometryType.TouchId ? "Touch ID" : "Face ID"
context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason, replyHandler);
// PIN/Passwordcontext.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, out var err2)
context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, localizedReason, replyHandler);
public UIDragItem[] GetItemsForBeginningDragSession(UITableView tableView,IUIDragSession session, NSIndexPath indexPath)
{var data = NSData.FromString(todoItems[indexPath.Row], NSStringEncoding.UTF8);
var itemProvider = new NSItemProvider();itemProvider.RegisterDataRepresentation(UTType.PlainText,
NSItemProviderRepresentationVisibility.All,(completion) =>{
completion(data, null);return null;
});var dragItem = new UIDragItem(itemProvider);return new UIDragItem[] { dragItem };
}
public bool CanHandleDropSession(UITableView tableView, IUIDropSession session){
return session.CanLoadObjects(typeof(NSString));}
public UITableViewDropProposal DropSessionDidUpdate(UITableView tableView, IUIDropSession session, NSIndexPath destinationIndexPath)
{if (tableView.HasActiveDrag) {
// moving in current app} else {
return new UITableViewDropProposal(UIDropOperation.Copy, UITableViewDropIntent.InsertAtDestinationIndexPath);
}}
public void PerformDrop(UITableView tableView, IUITableViewDropCoordinator coordinator){
// determine path from coordinator.DestinationIndexPath
coordinator.Session.LoadObjects<NSString>((items) =>{
tableView.BeginUpdates();foreach (var i in items){
// add items to table and data store}tableView.EndUpdates();
};}
// MKMarkerAnnotationViewClusteringIdentifier = "todo";
// ViewDidLoadMapView.Register(typeof(TodoView),MKMapViewDefault.AnnotationViewReuseIdentifier);MapView.Register(typeof(ClusterView),MKMapViewDefault.ClusterAnnotationViewReuseIdentifier);
// ClusterView : MKMarkerAnnotationViewvar renderer = new UIGraphicsImageRenderer(new CGSize(40, 40));var count = cluster.MemberAnnotations.Length;var notDoneCount = CountByType(cluster.MemberAnnotations, MarkerType.NotDone);
Image = renderer.CreateImage((context) => {// Fill full circle with tricycle colorTodoView.DoneColor.SetFill();UIBezierPath.FromOval(new CGRect(0, 0, 40, 40)).Fill();... Custom drawing
// MapView.GetViewForAnnotationif (annotation is TodoAnnotation) {
//...}else if (annotation is MKClusterAnnotation) {var cluster = annotation as MKClusterAnnotation;var view = mapView.DequeueReusableAnnotation
(MKMapViewDefault.ClusterAnnotationViewReuseIdentifier) as ClusterView;if (view == null) {view = new ClusterView(cluster,
MKMapViewDefault.ClusterAnnotationViewReuseIdentifier);}return view;
}
customvision.ai
developer.apple.com/machine-learning/
// Loadvar assetPath = NSBundle.MainBundle.GetUrlForResource("VGG16.mlmodelc");
var model = MLModel.Create(assetPath, out err);
// Classifyvar inputs = new NSDictionary<NSString, NSObject> (new NSString("image"), imageValue);
var inputFeatures = new MLDictionaryFeatureProvider (inputs, out error);
var outFeatures = model.GetPrediction (inputFeatures, out error2);
var predictionsDictionary = outFeatures.GetFeatureValue ("classLabelProbs").DictionaryValue;
Info.plist
developer.apple.com/support/app-store/
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)){
context.LocalizedReason = "Authorize for access to secrets";}
if (picker.RespondsToSelector(new Selector("setPredicateForEnablingPerson:")))
{picker.PredicateForEnablingPerson = NSPredicate.FromFormat
("emailAddresses.@count > 0");}
aka.ms/xamarin/ios11-todo11
aka.ms/xamarin/ios11
aka.ms/xamarin/ios11-samples
visualstudio.com/xamarin
Craig Dunn
Microsoft Docs