{"id":142,"date":"2009-04-24T17:24:49","date_gmt":"2009-04-24T16:24:49","guid":{"rendered":"http:\/\/www.paullynch.org\/blog\/?p=142"},"modified":"2009-04-24T17:24:49","modified_gmt":"2009-04-24T16:24:49","slug":"iphone-developer-tip-shake-it","status":"publish","type":"post","link":"http:\/\/www.paullynch.org\/blog\/?p=142","title":{"rendered":"iPhone developer tip &#8211; shake it!"},"content":{"rendered":"<p>Detecting shakes is easy.  Balancing the sensitivity so that a lighter shake is required forward and back to trigger an event than sideways, or up and down &#8211; that takes a bit more work.  Writing this code the first time will make your controller classes look like a mess, so it&#8217;s time to refactor that code.<\/p>\n<p>I have written this as a simple class called PLShaker, which you can drop into any app. \u00c2\u00a0It has one property, a float called &#8216;violence&#8217;, which is a sensitivity scaling parameter, and the default value is 1.5 (more means less sensitive, so it&#8217;s not really well named).<\/p>\n<p>To use this class, register to receive a notification from it:<\/p>\n<p><code> shaker = [[PLShaker alloc] init];<br \/>\n[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clear:) name:@\"PLShaker.Shake\" object:nil];<\/code><\/p>\n<p>The @selector should be a method that takes a NSNotification argument (actually, with ObjC this doesn&#8217;t matter, but that&#8217;s the value that will be passed to you &#8211; there&#8217;s no user data, so you can&#8217;t do a whole lot with it).<\/p>\n<p>For me, most of the time the main use is to clear a form if the device is shaken, which is \u00c2\u00a0a method that doubles up as an action.<\/p>\n<p><a href=\"http:\/\/www.paullynch.org\/iphone\/PLShaker.zip\">PLShaker.h\/PLShaker.m<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Detecting shakes is easy. Balancing the sensitivity so that a lighter shake is required forward and back to trigger an event than sideways, or up and down &#8211; that takes a bit more work. Writing this code the first time will make your controller classes look like a mess, so it&#8217;s time to refactor that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[21],"class_list":["post-142","post","type-post","status-publish","format-standard","hentry","category-programming-for-apples","tag-iphone"],"_links":{"self":[{"href":"http:\/\/www.paullynch.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.paullynch.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.paullynch.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.paullynch.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.paullynch.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=142"}],"version-history":[{"count":0,"href":"http:\/\/www.paullynch.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/142\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.paullynch.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.paullynch.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.paullynch.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}