Cocoa Touch 的新特性

Storyboard

  • SizeClass
Cocoa Touch 的新特性_第1张图片
sizeClass.jpg
Cocoa Touch 的新特性_第2张图片
vary.jpg

Session 222 - Making Apps Adaptive, Part 1
Session 233 - Making Apps Adaptive, Part 2

  • Autolayout

GCD

let queue = DispatchQueue(label: ”com.example.queue")
  queue.async {
}

let mainQueue = DispatchQueue.main
let gloabelQueue = DispatchQueue.global()

Session 720 - Concurrent Programming With GCD in Swift 3

Core Graphics

if let ctx = UIGraphicsGetCurrentContext() {
  let rectangle = CGRect(x: 0, y: 0, width: 512, height: 512)
  ctx.setFillColor(UIColor.blue().cgColor)
  ctx.setStrokeColor(UIColor.white().cgColor)
  ctx.setLineWidth(10)
  ctx.addRect(rectangle)
  ctx.drawPath(using: .fillStroke)
  
  UIGraphicsEndImageContext()
}

Image Renderer

  • 以前:
 func createDrawing(size: CGSize) -> UIImage {
   let renderer = UIGraphicsBeginImageContext(size)
   // Do your drawing here
   let image = UIGraphicsGetImageFromCurrentImageContext()
   UIGraphicsEndImageContext()
   return image
}
  • 现在:
func createDrawing(size: CGSize) -> UIImage {
   let renderer = UIGraphicsImageRenderer(size: size)
   return renderer.image { rendererContext in
    } 
  }  

func createPdf(bounds: CGRect, to url: URL) {
  let renderer = UIGraphicsPDFRenderer(bounds: bounds)
  
  try? renderer.writePDF(to: url) { rendererContext in
    
  }
}

Speech Recognition

import Speech

let recognizer = SFSpeechRecognizer()
let request = SFSpeechURLRecognitionRequest(url: audioFileURL)
recognizer?.recognitionTask(with: request, resultHandler: { (result, error) in
     print (result?.bestTranscription.formattedString)
})

Session 509 - Speech Recognition API

Dynamic Type

  • 支持 label, textView,controls
label.font = UIFont.preferredFont(forTextStyle: UIFontTextStyleBody)
label.adjustsFontForContentSizeCategory = true
Cocoa Touch 的新特性_第3张图片
dynamic type.jpg

Tab bar items

  • 可以自定义badge color, text attribute, unselected tint color
tabBarItem.badgeColor = UIColor.white()
badgeTextAttributes = [ NSForegroundColorAttributeName : UIColor.blue(), 
NSFontAttributeName : UIFont.italicSystemFont(ofSize: 12) ] tabBarItem.setBadgeTextAttributes(textAttributes: badgeTextAttributes, 
                                    forState: UIControlStateNormal)
tabBar.unselectedTintColor = UIColor.brown()
tabbar item.jpg

UIViewPropertyAnimator

let timing = UICubicTimingParameters(animationCurve: .easeInOut) 
let animator = UIViewPropertyAnimator(duration: duration, timingParameters: timing)
animator.addAnimations { 
self.squareView.center = CGPoint(x: point.x, y: point.y) 
}
animator.startAnimation()

Session 216 - Advances in UIKit Animations and Transitions

ReplayKit

  • 支持直播

Go Live with ReplayKit

你可能感兴趣的:(Cocoa Touch 的新特性)