View
261
Download
2
Category
Preview:
Citation preview
func addObserver(observer: AnyObject, selector aSelector: Selector, name aName: String?, object anObject: AnyObject?)
⽅方法2:
發送notification時所在的thread,即是執⾏行Selector的thread
發送notification
func postNotification(notification: NSNotification)
func postNotificationName(aName: String, object anObject: AnyObject?) func postNotificationName(aName: String, object anObject: AnyObject?, userInfo aUserInfo: [NSObject : AnyObject]?)
移除notification
func removeObserver(observer: AnyObject)
func removeObserver(observer: AnyObject, name aName: String?, object anObject: AnyObject?)
沒有remove,notification傳送給死去的物件會crash
特例: controller在死去時會⾃自動remove
UIApplicationDidFinishLaunchingNotification會在 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool執⾏行完後才被呼叫。
UIApplication
@property(nonatomic) NSInteger applicationIconBadgeNumber;
var statusBarFrame: CGRect { get }
預設⾼高度20,開啟熱點時變40
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
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" }
接收Notificationoverride 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)" } } }
X Y Z
直立的方向home按鈕在下方螢幕和地板垂直
0 -1 0
直立的方向home按鈕在上方螢幕和地板垂直
0 1 0
水平的方向右長邊在下螢幕和地板垂直
1 0 0
水平的方向右長邊在上螢幕和地板垂直
-1 0 0
螢幕面對天花板 0 0 -1
螢幕面對地板 0 0 1
(1) 將iPhone傾向下短邊。
結果: y < 0
(2) 將iPhone傾向上短邊。
結果: y > 0
(3) 將iPhone傾向左長邊。
結果: x < 0
(4) 將iPhone傾向右長邊。
結果: x > 0
iPhone繞著從天⽽而降的重⼒力⽅方向旋轉, -> 偵偵到的x, y, z值維持定值
lazy var blockBehavior: UIDynamicItemBehavior = { let lazilyCreatedBlockBehavior = UIDynamicItemBehavior() lazilyCreatedBlockBehavior.allowsRotation = true lazilyCreatedBlockBehavior.elasticity = 0.85 lazilyCreatedBlockBehavior.friction = 0 lazilyCreatedBlockBehavior.resistance = 0 return lazilyCreatedBlockBehavior }()
let motionManager = AppDelegate.Motion.Manager if motionManager.accelerometerAvailable { motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.mainQueue()) { (data, error) -> Void in self.bouncer.gravity.gravityDirection = CGVector(dx: data.acceleration.x, dy: -data.acceleration.y) } }
如何知道使⽤用者reject(⽐比猜出表⽩白被reject簡單)
[CLLocationManager authorizationStatus];
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status;
當使⽤用者點選權限詢問視窗後觸發
算距離
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location ;
公尺
可從經緯度建⽴立CLLocation物件
Recommended