Standford 2015 week8
- 27. Document Types &
Imported UTIs
http://www.infragistics.com/community/blogs/stevez/archive/2013/03/04/associate-a-file-type-
with-your-ios-application.aspx
https://developer.apple.com/library/ios/documentation/Miscellaneous/Reference/UTIRef/
Articles/System-DeclaredUniformTypeIdentifiers.html#//apple_ref/doc/uid/TP40009259-SW1
http://www.infragistics.com/community/blogs/stevez/archive/2013/03/05/ios-tips-and-tricks-
associate-a-file-type-with-your-app-part-2.aspx
- 29. func application(application: UIApplication, handleOpenURL url: NSURL)
-> Bool
{
// post a notification when a GPX file arrives
let center = NSNotificationCenter.defaultCenter()
let notification = NSNotification(name: GPXURL.Notification,
object: self, userInfo: [GPXURL.Key:url])
center.postNotification(notification)
return true
}
center.postNotificationName(GPXURL.Notification, object: self,
userInfo: [GPXURL.Key:url])
發送Notification
也可以
struct GPXURL {
static let Notification = "GPXURL Radio Station"
static let Key = "GPXURL URL Key"
}
- 30. 接收Notification
override func viewDidLoad() {
super.viewDidLoad()
// sign up to hear about GPX files arriving
let center = NSNotificationCenter.defaultCenter()
let queue = NSOperationQueue.mainQueue()
let appDelegate = UIApplication.sharedApplication().delegate
center.addObserverForName(GPXURL.Notification, object:
appDelegate, queue: queue) { notification in
if let url = notification?.userInfo?[GPXURL.Key] as? NSURL
{
self.textView.text = "Received (url)"
}
}
}
- 36. (1) 將iPhone傾向下短邊。
結果: y < 0
(2) 將iPhone傾向上短邊。
結果: y > 0
(3) 將iPhone傾向左長邊。
結果: x < 0
(4) 將iPhone傾向右長邊。
結果: x > 0
iPhone繞著從天⽽而降的重⼒力⽅方向旋轉,
-> 偵偵到的x, y, z值維持定值
- 45. lazy var blockBehavior: UIDynamicItemBehavior = {
let lazilyCreatedBlockBehavior = UIDynamicItemBehavior()
lazilyCreatedBlockBehavior.allowsRotation = true
lazilyCreatedBlockBehavior.elasticity = 0.85
lazilyCreatedBlockBehavior.friction = 0
lazilyCreatedBlockBehavior.resistance = 0
return lazilyCreatedBlockBehavior
}()
- 46. let motionManager = AppDelegate.Motion.Manager
if motionManager.accelerometerAvailable {
motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.mainQu
eue()) { (data, error) -> Void in
self.bouncer.gravity.gravityDirection = CGVector(dx:
data.acceleration.x, dy: -data.acceleration.y)
}
}