{"id":368,"date":"2015-04-21T12:13:04","date_gmt":"2015-04-21T04:13:04","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=368"},"modified":"2016-07-15T17:19:29","modified_gmt":"2016-07-15T09:19:29","slug":"ios%e6%91%87%e4%b8%80%e6%91%87%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2015\/04\/21\/121304368.html","title":{"rendered":"iOS\u6447\u4e00\u6447\u7684\u4f7f\u7528"},"content":{"rendered":"<p><strong>\u4e00\u3001\u5b9e\u73b0\u7cfb\u7edf\u81ea\u5e26\u7684motionBegan\u65b9\u6cd5<\/strong><\/p>\n<pre lang=\"objc\" line=\"1\">\/\/\/ \u5f00\u59cb\n- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0);\n\/\/\/ \u7ed3\u675f\n- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0);\n\/\/\/ \u53d6\u6d88\n- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0);<\/pre>\n<p>\u5047\u5982\u7a0b\u5e8f\u4e0d\u54cd\u5e94\u6b64\u65b9\u6cd5\uff0c\u518d\u5b9e\u73b0\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<pre lang=\"objc\" line=\"1\">- (BOOL)canBecomeFirstResponder\n{\n    return YES;\n}<\/pre>\n<p><!--more--><br \/>\n<strong>\u4e8c\u3001motionBegan+\u901a\u77e5\u7684\u65b9\u6cd5\uff08\u5efa\u8bae\uff09<\/strong><\/p>\n<p>1.\u5728Appdelegate\u91cc\u5199motionBegan\u65b9\u6cd5<\/p>\n<pre lang=\"objc\" line=\"1\">-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event\n{\n    [[NSNotificationCenter defaultCenter] postNotificationName:@\"SAMotionBegan\" object:@(motion)];\n}<\/pre>\n<p>2.\u5728\u9700\u8981\u63a5\u6536\u901a\u77e5\u7684\u9875\u9762\u6dfb\u52a0\u901a\u77e5<\/p>\n<pre lang=\"objc\" line=\"1\">- (void)viewWillAppear:(BOOL)animated\n{\n    [super viewWillAppear:animated];\n    [SANotice addObserver:self selector:@selector(shake) name:@\"SAMotionBegan\" object:nil];\n}\n \n- (void)shake\n{\n    SALog(@\"\u6447\u4e00\u6447\u5f00\u59cb...\");\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u5b9e\u73b0\u7cfb\u7edf\u81ea\u5e26\u7684motionBegan\u65b9\u6cd5 \/\/\/ \u5f00\u59cb &#8211; (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0); \/\/\/ \u7ed3\u675f &#8211; (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0); \/\/\/ \u53d6\u6d88 &#8211; (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0); \u5047\u5982\u7a0b\u5e8f\u4e0d\u54cd\u5e94\u6b64\u65b9\u6cd5\uff0c\u518d\u5b9e\u73b0\u4ee5\u4e0b\u65b9\u6cd5\uff1a &#8211; (BOOL)canBecomeFirstResponder { return YES; }<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[20,17],"class_list":["post-368","post","type-post","status-publish","format-standard","hentry","category-project","tag-basics","tag-skill"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=368"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/368\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}