﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-佳为好友</title><link>http://www.cppblog.com/walkklookk/</link><description /><language>zh-cn</language><lastBuildDate>Tue, 14 Apr 2026 23:09:01 GMT</lastBuildDate><pubDate>Tue, 14 Apr 2026 23:09:01 GMT</pubDate><ttl>60</ttl><item><title>原:Mindjet文件导出</title><link>http://www.cppblog.com/walkklookk/archive/2013/01/11/197201.html</link><dc:creator>佳为好友</dc:creator><author>佳为好友</author><pubDate>Fri, 11 Jan 2013 08:48:00 GMT</pubDate><guid>http://www.cppblog.com/walkklookk/archive/2013/01/11/197201.html</guid><wfw:comment>http://www.cppblog.com/walkklookk/comments/197201.html</wfw:comment><comments>http://www.cppblog.com/walkklookk/archive/2013/01/11/197201.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/walkklookk/comments/commentRss/197201.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/walkklookk/services/trackbacks/197201.html</trackback:ping><description><![CDATA[创建:2013年01月11日<br /><br />Mindjet的免费账号的文件无法导出.<br /><br />可以绕过,方法如下:<br /># 可以使用iphone同步之.<br /># 然后,用iFunBox打开iphone程序的Documents文档. 见名知意,将需要的文件夹导出.<br /># 导出的文件虽然没有文件名,但是其实是mmap文件.改名即可.<br /># 使用其他兼容软件打卡mmap文件.<br /><br />+++++<img src ="http://www.cppblog.com/walkklookk/aggbug/197201.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/walkklookk/" target="_blank">佳为好友</a> 2013-01-11 16:48 <a href="http://www.cppblog.com/walkklookk/archive/2013/01/11/197201.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转:6 Ways to Force Quit Mac Applications</title><link>http://www.cppblog.com/walkklookk/archive/2013/01/04/196938.html</link><dc:creator>佳为好友</dc:creator><author>佳为好友</author><pubDate>Fri, 04 Jan 2013 05:44:00 GMT</pubDate><guid>http://www.cppblog.com/walkklookk/archive/2013/01/04/196938.html</guid><wfw:comment>http://www.cppblog.com/walkklookk/comments/196938.html</wfw:comment><comments>http://www.cppblog.com/walkklookk/archive/2013/01/04/196938.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/walkklookk/comments/commentRss/196938.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/walkklookk/services/trackbacks/196938.html</trackback:ping><description><![CDATA[创建:2013年01月04日<br /><br />转:http://osxdaily.com/2012/03/02/force-quit-mac-apps/<br /><br /><p style="margin: 0px 0px 10px; padding: 0px; color: #303030; font-family: 'Helvetica Neue', Verdana, Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 22.266666412353516px; background-color: #ffffff;"><img src="http://cdn.osxdaily.com/wp-content/uploads/2012/03/force-quit-mac.jpg" alt="Force Quit on a Mac" title="force-quit-mac" width="620" height="312" size-full=""  wp-image-27917"="" style="display: block !important; margin: 3px 10px 3px 0px; float: left; border: 1px solid #ffffff;" /></p><p style="margin: 0px 0px 10px; padding: 0px; color: #303030; font-family: 'Helvetica Neue', Verdana, Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 22.266666412353516px; background-color: #ffffff;"><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />Is your Mac seeing the infamously dreaded spinning beachball of death? Is an app failing to respond? Maybe you have an errant process or two? Here are six ways for apps to be force quit on a Mac, remember a few keyboard shortcuts or sequences now and save yourself a hassle later.</p><h2>1) Force Quit Currently Active Mac App with the Keyboard</h2><p style="margin: 0px 0px 10px; padding: 0px; color: #303030; font-family: 'Helvetica Neue', Verdana, Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 22.266666412353516px; background-color: #ffffff;">Hold down&nbsp;<strong>Command+Option+Shift+Escape</strong>&nbsp;for a second or two until the app forcibly closes. This is the quickest way to force quit the foreground application in Mac OS X and a very good keyboard shortcut to remember.</p><h2>2) Bring Up the &#8220;Force Quit Applications&#8221; Window</h2><p style="margin: 0px 0px 10px; padding: 0px; color: #303030; font-family: 'Helvetica Neue', Verdana, Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 22.266666412353516px; background-color: #ffffff;">Hit&nbsp;<strong>Command+Option+Escape</strong>&nbsp;to bring up the simple &#8220;Force Quit Applications&#8221; window, then click to select the app name, followed by clicking the &#8220;Force Quit&#8221; button to end the app immediately. Think of this as a simplified version of Activity Monitor, and it&#8217;s also a great&nbsp;<a href="http://osxdaily.com/2012/03/02/force-quit-mac-apps/#" id="KonaLink0" style="color: #0072bc; cursor: pointer; margin: 0px; top: 0px; right: 0px; bottom: 0px; left: 0px; outline: none; padding: 0px; position: static; background-color: transparent !important; font-family: inherit !important; border: 0px none transparent !important; background-image: none !important; display: inline !important; font-size: inherit !important;"><span style="border-bottom-width: 1px; border-bottom-style: solid; background-image: none; background-color: transparent; position: static; border-top-width: 0px !important; border-top-style: none !important; border-left-width: 0px !important; border-left-style: none !important; border-right-width: 0px !important; border-right-style: none !important; padding: 0px 0px 1px !important; width: auto !important; font-family: inherit !important; font-size: inherit !important;">keystroke</span></a>&nbsp;to remember to use since it allows for quickly ceasing multiple apps.</p><h2>3) Force Quitting Apps from the Dock</h2><p style="margin: 0px 0px 10px; padding: 0px; color: #303030; font-family: 'Helvetica Neue', Verdana, Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 22.266666412353516px; background-color: #ffffff;"><strong>Option + Right Click</strong>&nbsp;on an apps icon in the Dock to bring up the &#8220;Force Quit&#8221; option, selecting this will kill the app without any confirmation.</p><h2>4) Force Quit from the Apple Menu</h2><p style="margin: 0px 0px 10px; padding: 0px; color: #303030; font-family: 'Helvetica Neue', Verdana, Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 22.266666412353516px; background-color: #ffffff;"><strong>Hold the Shift Key</strong>&nbsp;and click on the  Apple menu to find &#8220;Force Quit [Application Name]&#8220;. This is easy to remember but not necessarily the most powerful method, since sometimes an application is completely unresponsive and the menus are inaccessible.</p><h2>5) Use Activity Monitor to Force Quit Apps</h2><p style="margin: 0px 0px 10px; padding: 0px; color: #303030; font-family: 'Helvetica Neue', Verdana, Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 22.266666412353516px; background-color: #ffffff;">Bring up Spotlight with Command+Space and then type Activity Monitor. Select the process name or ID you wish to kill (unresponsive apps will usually appear as red), and hit the red &#8220;Quit Process&#8221; button. Think of this as the Mac equivalent to a&nbsp;<a href="http://osxdaily.com/2010/08/15/mac-task-manager/" style="background-color: inherit; color: #2266bb; font-weight: bold;">task manager</a>&nbsp;from the Windows world and a more complex version of the second tips Force Quit window. If one of the previous methods fails, this will almost certainly work.<br /><img src="http://cdn.osxdaily.com/wp-content/uploads/2012/03/force-quit-activity-monitor.jpg" alt="Force Quit Mac Apps from the Activity Monitor" title="force-quit-activity-monitor" width="600" height="214" size-full=""  wp-image-27913"="" style="display: block !important; margin: 3px 10px 3px 0px; float: left; border: 1px solid #ffffff;" /></p><h2>6) Using the Terminal &amp; kill Command</h2><p style="margin: 0px 0px 10px; padding: 0px; color: #303030; font-family: 'Helvetica Neue', Verdana, Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 22.266666412353516px; background-color: #ffffff;">If all else fails, using the command line is a surefire way to force an app or process to quit by issuing the low-level kill command. Launch the Terminal and type one of the following commands:</p><p style="margin: 0px 0px 10px; padding: 0px; color: #303030; font-family: 'Helvetica Neue', Verdana, Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 22.266666412353516px; background-color: #ffffff;"><code style="background-color: #f3f3f3; padding: 3px; font-size: 1.2em; border: 1px solid #dddddd; display: block;">killall [processname]</code></p><p style="margin: 0px 0px 10px; padding: 0px; color: #303030; font-family: 'Helvetica Neue', Verdana, Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 22.266666412353516px; background-color: #ffffff;">For example, &#8220;killall Safari&#8221; would kill all instances of the Safari process. If you know the process id, which you can find with the ps or &#8216;ps aux&#8217; command. Aim kill at that process specifically:</p><p style="margin: 0px 0px 10px; padding: 0px; color: #303030; font-family: 'Helvetica Neue', Verdana, Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 22.266666412353516px; background-color: #ffffff;"><code style="background-color: #f3f3f3; padding: 3px; font-size: 1.2em; border: 1px solid #dddddd; display: block;">kill -9 [pid]</code></p><p style="margin: 0px 0px 10px; padding: 0px; color: #303030; font-family: 'Helvetica Neue', Verdana, Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 22.266666412353516px; background-color: #ffffff;">The kill commands will take out just about anything, and sometimes have the side effect of not honoring Versions, Window Restore, and Auto-Save, so be cautious of potential data loss.</p><h2>Bonus: Force Quit on iOS</h2><p style="margin: 0px 0px 10px; padding: 0px; color: #303030; font-family: 'Helvetica Neue', Verdana, Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 22.266666412353516px; background-color: #ffffff;">OK it&#8217;s not quite the Mac, but it&#8217;s useful to know for mobile users: from the iOS side of things, you can&nbsp;<a href="http://osxdaily.com/2012/02/14/force-quit-app-iphone-ipad-ipod-touch/" style="background-color: inherit; color: #2266bb; font-weight: bold;">force quit apps on iPhone, iPad</a>, or iPod touch, by holding down the Power button until the slide to power option appears, and then hold the Home button until the app closes.</p>+++++<img src ="http://www.cppblog.com/walkklookk/aggbug/196938.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/walkklookk/" target="_blank">佳为好友</a> 2013-01-04 13:44 <a href="http://www.cppblog.com/walkklookk/archive/2013/01/04/196938.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>原： UISearchDisplayController重用 2</title><link>http://www.cppblog.com/walkklookk/archive/2012/12/30/196850.html</link><dc:creator>佳为好友</dc:creator><author>佳为好友</author><pubDate>Sun, 30 Dec 2012 03:43:00 GMT</pubDate><guid>http://www.cppblog.com/walkklookk/archive/2012/12/30/196850.html</guid><wfw:comment>http://www.cppblog.com/walkklookk/comments/196850.html</wfw:comment><comments>http://www.cppblog.com/walkklookk/archive/2012/12/30/196850.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/walkklookk/comments/commentRss/196850.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/walkklookk/services/trackbacks/196850.html</trackback:ping><description><![CDATA[<span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">创建：2011.03.03</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><div style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><br />UISearchDisplayController重用<br /><br />如果2个页面使用同样的搜索逻辑和界面，<wbr>则可以考虑重用UISearchDisplayControll<wbr>er。<br />或者，如果你的搜索页面和平时显示的页面完全不同，<wbr>又不想把这两个逻辑放在一个ViewController里面，<wbr>则也可以使用这种方法。<br /><br />#<wbr>UISearchDisplayController一般都是通<wbr>过IB进行配置的。<wbr>加入SearchBar以及UISearchDisplayCo<wbr>ntroller。<br /><br />#<wbr>在Xib中加入重用的SearchResultViewCont<wbr>roller。<br /><br />#<wbr>在FileOwner中为SearchResultViewCo<wbr>ntroller加入一个IBOutlet。<br /><br />#<wbr>将SearchBar的delegate设定为SearchRe<wbr>sultViewController。<br /><br />#<wbr>将UISearchDisplayController的del<wbr>egate，tableViewDataSource，<wbr>TableViewDelegate设定为SearchResu<wbr>ltViewController。<br /><br />#<wbr>一定不要将UISearchDisplayController<wbr>的searchContentViewController设定<wbr>为SearchResultViewController，<wbr>而要设定为默认的self，否则无法显示Search页面。<wbr>多次测试才发现这个问题的。<br /><br /># 将SearchResultViewController的se<wbr>archDisplayController设定为UISear<wbr>chDisplayController。<br /><br /># 然后，就按照正常的操作进行控制吧。<br /><br />+++++</div><img src ="http://www.cppblog.com/walkklookk/aggbug/196850.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/walkklookk/" target="_blank">佳为好友</a> 2012-12-30 11:43 <a href="http://www.cppblog.com/walkklookk/archive/2012/12/30/196850.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转：Sizes of iPhone UI Elements</title><link>http://www.cppblog.com/walkklookk/archive/2012/12/30/196849.html</link><dc:creator>佳为好友</dc:creator><author>佳为好友</author><pubDate>Sun, 30 Dec 2012 03:43:00 GMT</pubDate><guid>http://www.cppblog.com/walkklookk/archive/2012/12/30/196849.html</guid><wfw:comment>http://www.cppblog.com/walkklookk/comments/196849.html</wfw:comment><comments>http://www.cppblog.com/walkklookk/archive/2012/12/30/196849.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/walkklookk/comments/commentRss/196849.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/walkklookk/services/trackbacks/196849.html</trackback:ping><description><![CDATA[<span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">创建：2011.03.03</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">转：</span><a href="http://www.idev101.com/code/User_Interface/sizes.html" target="_blank" style="color: #1155cc; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">http://www.idev101.com/code/<wbr>User_Interface/sizes.html</a><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><h2>Sizes of iPhone UI Elements</h2><div style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><p><img src="http://www.idev101.com/code/User_Interface/sizes.png" alt="" height="742" width="630" /></p><table><tbody><tr><th style="background-color: #eeeeee;">Element</th><th style="background-color: #eeeeee;">Size (in points)</th></tr><tr><td style="margin: 0px;">Window (including status bar)</td><td style="margin: 0px;">320 x 480 pts</td></tr><tr><td style="margin: 0px;">Status Bar<br />(<a href="http://www.idev101.com/code/User_Interface/UIStatusBar.html" target="_blank" style="color: #1155cc;">How to hide the status bar</a>)</td><td style="margin: 0px;">20 pts</td></tr><tr><td style="margin: 0px;">View inside window&nbsp;<br />(visible status bar)</td><td style="margin: 0px;">320 x 460</td></tr><tr><td style="margin: 0px;">Navigation Bar</td><td style="margin: 0px;">44 pts</td></tr><tr><td style="margin: 0px;">Nav Bar Image /<br />Toolbar Image</td><td style="margin: 0px;">up to 20 x 20 pts (transparent PNG)</td></tr><tr><td style="margin: 0px;">Tab Bar</td><td style="margin: 0px;">49 pts</td></tr><tr><td style="margin: 0px;">Tab Bar Icon</td><td style="margin: 0px;">up to 30 x 30 pts (transparent PNGs)</td></tr><tr><td style="margin: 0px;">Text Field</td><td style="margin: 0px;">31 pts</td></tr><tr><td style="margin: 0px;">Height of a view inside&nbsp;<br />a navigation bar</td><td style="margin: 0px;">416 pts</td></tr><tr><td style="margin: 0px;">Height of a view inside&nbsp;<br />a tab bar</td><td style="margin: 0px;">411 pts</td></tr><tr><td style="margin: 0px;">Height of a view inside&nbsp;<br />a navbar&nbsp;<em>and</em>&nbsp;a tab bar</td><td style="margin: 0px;">367 pts</td></tr><tr><td style="margin: 0px;">Portrait Keyboard height</td><td style="margin: 0px;">216 pts</td></tr><tr><td style="margin: 0px;">Landscape Keyboard height</td><td style="margin: 0px;">140 pts</td></tr></tbody></table><h3>Points vs. Pixels</h3><p>The iPhone 4 introduced a high resolution display with twice the pixels of previous iPhones. However you don't have to modify your code to support high-res displays; the coordinate system goes by points rather than pixels, and the dimensions in points of the screen and all UI elements remain the same.</p><p>iOS 4 supports high resolution displays (like the iPhone 4 display) via the&nbsp;scale&nbsp;property on UIScreen, UIView, UIImage, and CALayer classes. If the object is displaying high-res content, its scale property is set to 2.0. Otherwise it defaults to 1.0.</p><p>All you need to do to support high-res displays is to provide @2x versions of the images in your project. See the&nbsp;<a href="http://www.idev101.com/code/Distribution/updating_ios4.html#l2" target="_blank" style="color: #1155cc;">checklist for updating to iOS4</a>&nbsp;or Apple documentation for&nbsp;<a href="http://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/SupportingHiResScreens/SupportingHiResScreens.html" target="_blank" style="color: #1155cc;">Supporting High Resolution Screens</a>&nbsp;for more info.</p><h3>Adjusting Sizes</h3><p>Click here to see how to adjust&nbsp;<a href="http://www.idev101.com/code/User_Interface/view_frames_bounds.html" target="_blank" style="color: #1155cc;">View Frames and Bounds</a>.</p><h3>Additional References</h3><ul><li style="margin-left: 15px;">Apple Documentation:&nbsp;<a href="http://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GraphicsDrawingOverview/GraphicsDrawingOverview.html#//apple_ref/doc/uid/TP40010156-CH14-SW7" target="_blank" style="color: #1155cc;">Points vs. Pixels</a></li><li style="margin-left: 15px;">Apple Documentation:&nbsp;<a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIBarButtonItem_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40007519-CH3-SW3" target="_blank" style="color: #1155cc;">UIBarButtonItem Class Reference</a>&nbsp;says "Typically, the size of a toolbar and navigation bar image is 20 x 20 points."</li><li style="margin-left: 15px;">Apple Documentation:&nbsp;<a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITabBarItem_Class/Reference/Reference.html#//apple_ref/occ/instm/UITabBarItem/initWithTitle:image:tag:" target="_blank" style="color: #1155cc;">UITabBarItem Class Reference</a>&nbsp;says "The size of an tab bar image is typically 30 x 30 points."</li></ul><br clear="all" /><p><a style="color: #1155cc;">Top</a>&nbsp;&#8226;&nbsp;<a href="http://www.idev101.com/" target="_blank" style="color: #1155cc;">Home</a></p></div><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">＋＋＋＋＋</span><img src ="http://www.cppblog.com/walkklookk/aggbug/196849.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/walkklookk/" target="_blank">佳为好友</a> 2012-12-30 11:43 <a href="http://www.cppblog.com/walkklookk/archive/2012/12/30/196849.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>原：UIScrollView使用Xib或IB布局</title><link>http://www.cppblog.com/walkklookk/archive/2012/12/30/196848.html</link><dc:creator>佳为好友</dc:creator><author>佳为好友</author><pubDate>Sun, 30 Dec 2012 03:42:00 GMT</pubDate><guid>http://www.cppblog.com/walkklookk/archive/2012/12/30/196848.html</guid><wfw:comment>http://www.cppblog.com/walkklookk/comments/196848.html</wfw:comment><comments>http://www.cppblog.com/walkklookk/archive/2012/12/30/196848.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/walkklookk/comments/commentRss/196848.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/walkklookk/services/trackbacks/196848.html</trackback:ping><description><![CDATA[<span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">创建：2011.03.04</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">UIScrollView使用xib布局后，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">要代码里面设定contentSize。否则无法滚动。</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">而且，在IB中也没有办法设定contentSize，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">因此只能通过代码设定。</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">＋＋＋＋＋</span><img src ="http://www.cppblog.com/walkklookk/aggbug/196848.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/walkklookk/" target="_blank">佳为好友</a> 2012-12-30 11:42 <a href="http://www.cppblog.com/walkklookk/archive/2012/12/30/196848.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转:Custom UIImagePickerController camera view -2</title><link>http://www.cppblog.com/walkklookk/archive/2012/12/30/196847.html</link><dc:creator>佳为好友</dc:creator><author>佳为好友</author><pubDate>Sun, 30 Dec 2012 03:42:00 GMT</pubDate><guid>http://www.cppblog.com/walkklookk/archive/2012/12/30/196847.html</guid><wfw:comment>http://www.cppblog.com/walkklookk/comments/196847.html</wfw:comment><comments>http://www.cppblog.com/walkklookk/archive/2012/12/30/196847.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/walkklookk/comments/commentRss/196847.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/walkklookk/services/trackbacks/196847.html</trackback:ping><description><![CDATA[<span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">修改：2011.04.02</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff; color: #3333ff;">【自：貌似这种方法，有时可能会被拒绝，有时候可以通过。<wbr>根据这篇文章：</span><br style="font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff; color: #3333ff;" /><span style="font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff; color: #3333ff;"><a href="http://www.juicybitssoftware.com/2009/11/07/static-analysis-rejection/" target="_blank" style="color: #1155cc;">http://www.juicybitssoftware.<wbr>com/2009/11/07/static-<wbr>analysis-rejection/</a></span><br style="font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff; color: #3333ff;" /><span style="font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff; color: #3333ff;">好像ios3.x就会被拒绝，而3.1以上就不会被拒绝。</span><br style="font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff; color: #3333ff;" /><span style="font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff; color: #3333ff;">原因是：在官方api中，只有在3.<wbr>1以上才有可以自定义界面的api。因此，苹果认为3.<wbr>1以下的自定义行为，都是非文档的。而3.1以上则就是正规的。<wbr>虽然，我们用的并不是正规方法，但是他们依然认为这是正规的。</span><br style="font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff; color: #3333ff;" /><span style="font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff; color: #3333ff;">】</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><div style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><br /><br />转:<a href="http://www.codza.com/custom-uiimagepickercontroller-camera-view" target="_blank" style="color: #1155cc;">http://www.codza.com/custom-<wbr>uiimagepickercontroller-<wbr>camera-view</a><br /><br /><h2><a href="http://www.codza.com/custom-uiimagepickercontroller-camera-view" title="custom UIImagePickerController camera view" target="_blank" style="color: #1155cc;">custom UIImagePickerController camera view</a></h2><div>January 12, 2009</div><div></div><h3><span style="color: #800000;">WARNING: While there are many apps (including some of mine) that use this technique, you should know some new apps and updates to existing apps have been rejected recently (april/2009). Please read the comments. So far I don&#8217;t know of any instances where the developer successfully argued Apple&#8217;s decision if the app was rejected.</span></h3><h3><span style="color: #800000;">With all that said, there&#8217;s still an outpour of apps that use this technique&#8230; so the decision is your.<br /></span></h3><p>Here is some information about inspecting and customizing the UIImagePickerController camera view. You can download the working xcode project with all the source code here:&nbsp;<a href="http://www.codza.com/files/customImagePicker.zip" target="_blank" style="color: #1155cc;">customImagePicker</a></p><p>I wanted to remove the top part of the interface (gray bacground and &#8220;Take Photo&#8221; label) for&nbsp;&nbsp;<a href="http://itunes.com/app/MeanPhoto" target="_blank" style="color: #1155cc;">Mean Photo</a>&nbsp;and&nbsp;<a href="http://itunes.com/app/NicePhoto" target="_blank" style="color: #1155cc;">Nice Photo</a>&nbsp;(version 1.2+). There is also a very annoying image shift between the camera view and the preview that I thought would be nice to fix.</p><p>You can download the&nbsp;<a href="http://www.codza.com/files/customImagePicker.zip" target="_blank" style="color: #1155cc;">customImagePicker</a>&nbsp;xcode project with all the source code that demonstrates these techniques. Run it on your iPhone in debug mode and check the log output for information.</p><p>CustomImagePicker is a subclass of UIImagePickerController. I override the<em>viewDidLoad:</em>&nbsp;method. When this method is called the view is ready to be customized (this approach was suggested in netsharc&#8217;s post&nbsp;<a href="http://netsharc.wordpress.com/2008/12/25/iphone-dev-creating-a-full-screen-camera-preview/" target="_blank" style="color: #1155cc;">here</a>.)</p><pre style="white-space: pre-wrap;">-(void) viewDidAppear: (BOOL)animated {<br />	// make sure to call the same method on the super class<br />	[super viewDidAppear:animated];<br /><br />	/* ... customize view here ... */<br />}</pre><p>The&nbsp;<em>inspectView::</em>&nbsp;method to recursively walks the view hierarchy and prints information about the views to the log: the class descriptions, the position and size and the path (talk about the path in a bit.) If you are interested in other information about the views, you can extend this method to print them. Here&#8217;s how this method is invoked:</p><pre style="white-space: pre-wrap;">[self inspectView:self.view depth:0 path:@""];</pre><p>You can uncomment this line in&nbsp;<em>viewDidLoad:</em>, but it&#8217;s also called from&nbsp;<em>previewCheck</em>every five seconds, so you can monitor the view hierarchy as it changes in the different states. So for example if you are interested what the view hierarchy is like in the preview mode, just take a photo and wait until the next dump appears in the log. The output looks something like this:</p><pre style="white-space: pre-wrap;"> .description: UILayoutContainerView: 0x125b90<br /> .frame: 0, 0, 320, 460<br /> .subviews: 2<br /><br /> --subview-- /0<br />   .description: UITransitionView: 0x1205a0<br />   .frame: 0, 0, 320, 460<br />   .subviews: 1<br /><br />     --subview-- /0/0<br />     .description: UIView: 0x125da0<br />     .frame: 0, 0, 320, 460<br />     .subviews: 1<br /><br />     --subview-- /0/0/0<br />       .description: PLCameraView: 0x125e50<br />       .frame: 0, 0, 320, 460<br />         .subviews: 4<br /><br />       --subview-- /0/0/0/0<br />         .description: UIView: 0x1264c0<br />         .frame: 0, 0, 320, 427<br />         .subviews: 0<br /><br />       --subview-- /0/0/0/1<br />         .description: UIImageView: 0x128850<br />           .class: UIImageView<br />         .frame: 10000, 10000, 320, 480<br />         .subviews: 0<br /><br />       --subview-- /0/0/0/2<br />         .description: UIView: 0x11b200<br />         .frame: 0, 0, 320, 33<br />         .subviews: 0<br />  <br />       --subview-- /0/0/0/3<br />         .description: PLCropOverlay: 0x127dc0<br />         .frame: 0, 0, 320, 460<br />         .subviews: 3<br /><br />         --subview-- /0/0/0/3/0<br />           .description: UIImageView: 0x12b2f0<br />             .class: UIImageView<br />           .frame: 0, 0, 320, 96<br />           .subviews: 0<br /><br />         --subview-- /0/0/0/3/1<br />           .description: PLCropLCDLayer: 0x12b350<br />           .frame: 0, 0, 320, 96<br />             .subviews: 0<br /><br />         --subview-- /0/0/0/3/2<br />           .description: TPBottomDualButtonBar: 0x12b5b0<br />           .frame: 0, 0, 320, 96<br />           .subviews: 2<br /><br />           --subview-- /0/0/0/3/2/0<br />               .description: TPPushButton: 0x12ba40<br />             .frame: 22, 22, 128, 47<br />             .subviews: 0<br /><br />           --subview-- /0/0/0/3/2/1<br />             .description: TPCameraPushButton: 0x12df10<br />               .frame: 170, 170, 128, 47<br />             .subviews: 1<br /><br />             --subview-- /0/0/0/3/2/1/0<br />               .description: UIImageView: 0x12e960<br />               .class: UIImageView<br />               .frame: 51, 51, 26, 19<br />                 .subviews: 0<br /><br /> --subview-- /1<br />   .description: UINavigationBar: 0x125a30<br />   .frame: 0, 0, 320, 44<br />   .subviews: 1<br /><br />   --subview-- /1/0<br />     .description: UINavigationItemView: 0x11abe0<br />       .frame: 160, 160, 0, 27<br />     .subviews: 0</pre><p>Confusing? It&#8217;s actually pretty simple (although not very pretty.)</p><p>Next to each subview you can see it&#8217;s path. For example&nbsp;<strong>/0/0/0/3</strong>&nbsp;means that it is subview #3 of subview #0 of subview #0 of subview #0. To look it up in the view hierarchy, just do this:</p><pre style="white-space: pre-wrap;">    UIView *theView = [[[[[[[[self.view subviews] objectAtIndex:0]<br />                                        subviews] objectAtIndex:0]<br />                                        subviews] objectAtIndex:0]<br />				        subviews] objectAtIndex:3];</pre><p>See the numbers next to&nbsp;<em>objectAtIndex:</em>? It&#8217;s&nbsp;<strong>/0/0/0/3</strong>&#8230; the path&#8230; So now you can look up any&nbsp;<em>UIView</em>&nbsp;from the hierarchy and modify it!</p><p>Even if the description shows that the class is part of the private iPhone libraries (eg.<em>PLCropLCDLayer</em>), it must be a subclass of&nbsp;<em>UIView</em>&nbsp;to be in the hierarchy. We don&#8217;t know (or at least not supposed to know) what methods the private library classes have, but they do have all the methods and properties of&nbsp;<em>UIView</em>. So we can make<em>theView</em>&nbsp;transparent or hidden like this (this is actually the path for the UI above the camera preview):</p><pre style="white-space: pre-wrap;">    [theView setAlpha:0.5];    // semi transparent<br />    [theView setHidden:YES];    // hidden</pre><p>I wanted to get rid of the gray bar and &#8220;Take Photo&#8221; label on top. The path for the gray background is&nbsp;<strong>/0/0/0/3/0</strong>, the label is&nbsp;<strong>/0/0/0/3/1</strong>. I look these up and animate their opacity (alpha) to 0:</p><pre style="white-space: pre-wrap;">    UIImageView *overlay = [[[[[[[[[[self.view subviews] objectAtIndex:0]<br />                                               subviews] objectAtIndex:0]<br />                                               subviews] objectAtIndex:0]<br />                                                 subviews] objectAtIndex:3]<br />                                               subviews] objectAtIndex:0];<br /><br />    UIView *label = [[[[[[[[[[self.view subviews] objectAtIndex:0]<br />                                          subviews] objectAtIndex:0]<br />                                        subviews] objectAtIndex:0]<br />                                        subviews] objectAtIndex:3]<br />                                        subviews] objectAtIndex:1];<br />  <br />    // animate their visibility (alpha) to 0 with a simple UIView animation<br />    //<br />    [UIView beginAnimations:nil context:nil];<br />    [overlay setAlpha:0.0];<br />    [label setAlpha:0.0];<br />    [UIView commitAnimations];</pre><p>Here&#8217;s what it looks like in&nbsp;<a href="http://itunes.com/app/NicePhoto" target="_blank" style="color: #1155cc;">Nice Photo</a>. The&nbsp;<a href="http://en.wikipedia.org/wiki/Love" target="_blank" style="color: #1155cc;"><strong>LOVE</strong></a>&nbsp;graphics is added in a separate view on top of the camera view.</p><div style="width: 234px;"><a href="http://itunes.com/app/nicephoto" target="_blank" style="color: #1155cc;"><img title="nicephotocamera" src="http://www.codza.com/wp-content/uploads/2009/01/nicephotocamera.jpg" alt="nicephotocamera" width="224" height="336" /></a><p>Nice Photo App with Camera UI tweaked</p></div><p>&nbsp;</p><p>The camera view is&nbsp;<strong>/0/0/0/0</strong>. To make it semi transparent (not sure why you would do this, but shows how to look it up):</p><pre style="white-space: pre-wrap;">    UIView *cameraView = [[[[[[[[self.view subviews] objectAtIndex:0]<br />                                           subviews] objectAtIndex:0]<br />                                           subviews] objectAtIndex:0]<br />                                             subviews] objectAtIndex:0];<br />    [cameraView setAlpha:0.5];</pre><p>You might be interested in button push events. The buttons are subclasses of<em>UIControl</em>, so you can easily add an action to them. For example to add an action to the camera button (TPCameraPushButton at&nbsp;<strong>/0/0/0/3/2/1</strong>):</p><pre style="white-space: pre-wrap;">    UIControl *captureButton = [[[[[[[[[[[[self.view subviews] objectAtIndex:0]<br />                                                     subviews] objectAtIndex:0]<br />                                                     subviews] objectAtIndex:0]<br />                                                       subviews] objectAtIndex:3]<br />                                                     subviews] objectAtIndex:2]<br />                                                     subviews] objectAtIndex:1];<br />  <br />    [captureButton addTarget:self action:@selector(<wbr>captureButtonAction:)<br />        forControlEvents:<wbr>UIControlEventTouchUpInside];</pre><p>(The&nbsp;<em>captureButtonAction:</em>&nbsp;method prints a message to the log when you tap the camera button in&nbsp;<a href="http://www.soymint.com/userfiles/file/soymint/customImagePicker.zip" target="_blank" style="color: #1155cc;">customImagePicker</a>.)</p><p>I wanted to fix the shift between the preview and the camera view. To do this, I have a timer calling the&nbsp;<em>previewCheck</em>&nbsp;method (I&#8217;m pretty sure there&#8217;s more elegant ways&#8230; but come ont, timers are cool!). The preview will be added to the UIView at&nbsp;<strong>/0/0/0/2</strong>. By default this view has no subviews, but subviews are added when in preview mode. Then I modify the transform of&nbsp;<strong>/0/0/0/2/0/0/0</strong>&nbsp;like such (btw this only makes sense in portrait mode):</p><pre style="white-space: pre-wrap;">    [previewImage setTransform:<wbr>CGAffineTransformTranslate(<br />        CGAffineTransformMakeScale(<wbr>320.0/1200, 320.0/1200),<br />                                   -12.0*1200/320,-17.0*1200/320)<wbr>];</pre><p>(Now you probably know why I was so interested in the view sizes&#8230; the view frames for the preview image are completely bizarre&#8230; hence the image shift. Are people allowed to drink on the job at&nbsp;<a href="http://finance.google.com/finance?client=ob&amp;q=NASDAQ:AAPL" target="_blank" style="color: #1155cc;">Apple</a>?)</p><p>You can experiment with other views. The&nbsp;<em>inspectView</em>&nbsp;method gives you a pretty good map of the hierarchy and it also works for other source types (like picking an image from the photo library.) Please look at the&nbsp;<a href="http://www.codza.com/files/customImagePicker.zip" target="_blank" style="color: #1155cc;">customImagePicker</a>&nbsp;xcode project, I added lots of comments (more than what I retyped here ;).</p><p>As always, feel free to&nbsp;<a title="contatc" href="http://www.codza.com/contact" target="_blank" style="color: #1155cc;">contact me</a>&#8230; and please check out&nbsp;<a href="http://www.meanvsnice.com/" target="_blank" style="color: #1155cc;">www.meanvsnice.com</a>&nbsp;for some shots taken with&nbsp;<a href="http://itunes.com/app/MeanPhoto" target="_blank" style="color: #1155cc;">Mean Photo</a>&nbsp;and&nbsp;<a href="http://itunes.com/app/NicePhoto" target="_blank" style="color: #1155cc;">Nice Photo</a>.</p><br />+++++</div><img src ="http://www.cppblog.com/walkklookk/aggbug/196847.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/walkklookk/" target="_blank">佳为好友</a> 2012-12-30 11:42 <a href="http://www.cppblog.com/walkklookk/archive/2012/12/30/196847.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>原：手势操作的一些规律</title><link>http://www.cppblog.com/walkklookk/archive/2012/12/30/196846.html</link><dc:creator>佳为好友</dc:creator><author>佳为好友</author><pubDate>Sun, 30 Dec 2012 03:41:00 GMT</pubDate><guid>http://www.cppblog.com/walkklookk/archive/2012/12/30/196846.html</guid><wfw:comment>http://www.cppblog.com/walkklookk/comments/196846.html</wfw:comment><comments>http://www.cppblog.com/walkklookk/archive/2012/12/30/196846.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/walkklookk/comments/commentRss/196846.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/walkklookk/services/trackbacks/196846.html</trackback:ping><description><![CDATA[<span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">日期：2011.04.09</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">原：手势操作的一些规律</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">*父view注册手势，则当手势操作在子view的时候，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">父view仍然能够收到消息。</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">*如果子view也注册了手势操作，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">则父view将无法收到手势操作了。可以猜测为，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">如果手势操作有下层拦截，则不会向上传递了。</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">*</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">使用UINavigationController的push加</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">入子Controller，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">那么即使RootController注册了手势操作，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">如果在子Controller进行手势操作时，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">Root也无法收到手势操作。</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">*在UITableView上注册手势操作也能成功。但是，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">由于UITableView自身有很多手势操作，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">因此可能会产生冲突，导致操作不受控制。例如，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">如果注册左右滑动的手势操作，则当进行左右操作时，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">很可能触发点击操作.</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">*如果某viewController覆盖了- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event等操作，则对于手势操作没有任何影响。</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">即仍然可以收到手势操作。同样，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">如果子view覆盖touchesBegan等函数，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">也不会妨碍父view接受手势操作的。总之，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">覆盖touchesBegan等函数，</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">不会对手势操作有任何影响。</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">*一些基本步骤：</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">- (void)viewDidLoad {</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">handleSwipeGestureRecognizer:)</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">];</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; [recognizer setDirection:(</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">UISwipeGestureRecognizerDirect</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">ionLeft)];</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; recognizer.</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">numberOfTouchesRequired = 1;</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; [[self view] addGestureRecognizer:</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">recognizer];</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; [recognizer release];</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">handleSwipeGestureRecognizer:)</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">];</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; [recognizer setDirection:(</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">UISwipeGestureRecognizerDirect</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">ionRight)];</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; recognizer.</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">numberOfTouchesRequired = 1;</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; [[self view] addGestureRecognizer:</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">recognizer];</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; [recognizer release];</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">}</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">- (void)</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">handleSwipeGestureRecognizer:(</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">UISwipeGestureRecognizer *)recognizer {</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; NSLog(@"</span><wbr style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">SecondViewGestureRecognizer");</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">}</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">＋＋＋＋＋</span><img src ="http://www.cppblog.com/walkklookk/aggbug/196846.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/walkklookk/" target="_blank">佳为好友</a> 2012-12-30 11:41 <a href="http://www.cppblog.com/walkklookk/archive/2012/12/30/196846.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转：手势操作-点击的不同次数引发的问题 －Differentiating Tap Counts on iOS</title><link>http://www.cppblog.com/walkklookk/archive/2012/12/30/196845.html</link><dc:creator>佳为好友</dc:creator><author>佳为好友</author><pubDate>Sun, 30 Dec 2012 03:41:00 GMT</pubDate><guid>http://www.cppblog.com/walkklookk/archive/2012/12/30/196845.html</guid><wfw:comment>http://www.cppblog.com/walkklookk/comments/196845.html</wfw:comment><comments>http://www.cppblog.com/walkklookk/archive/2012/12/30/196845.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/walkklookk/comments/commentRss/196845.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/walkklookk/services/trackbacks/196845.html</trackback:ping><description><![CDATA[<span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">日期：2011.04.09</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff; color: #3333ff;">【自：也就是说，当同时注册点击1次，点击2次，<wbr>点击3次的时候，会引发这样一个问题。即当识别点击三次的时候，<wbr>对于点击1，2次也会响应。对于新的方法，要使用-<wbr>requireGestureRecognizerToFail<wbr>:，对于就的ios要使用延迟处理了。】</span><br style="font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff; color: #3333ff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">转：</span><a href="http://www.cimgf.com/2010/06/14/differentiating-tap-counts-on-ios/" target="_blank" style="color: #1155cc; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">http://www.cimgf.com/2010/<wbr>06/14/differentiating-tap-<wbr>counts-on-ios/</a><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><p style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">In your iPhone/iPad apps you often need to know how many times your user tapped in a view. This can be challenging because, though the user may have tapped twice, you will receive the event and it will look like they tapped once as well as twice. If the user triple-tapped, you will get the event for one tap, two taps, and three taps. It can get a little frustrating, but the trick is timing. You simply have to wait a period of time to see if another tap comes. If it does, you cancel the action spawned by the first tap. If it doesn&#8217;t you allow the action to run. There&#8217;s a few little nuances to getting it to work, but it can be done. Here is how.</p><h2>Overriding Touch Event Handlers</h2><p style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">In order to know how many times your user tapped, you listen for the events in the various touch handlers. Let start with -touchesEnded. This is where we will determine how many taps we received and respond accordingly. Consider the following code.</p><div style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><table><tbody><tr><td style="margin: 0px;"><pre style="white-space: pre-wrap;">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></pre></td><td style="margin: 0px;"><pre style="white-space: pre-wrap;"><span style="color: #002200;">-</span> <span style="color: #002200;">(</span><span style="color: #a61390;">void</span><span style="color: #002200;">)</span>touchesEnded<span style="color: #002200;">:</span><span style="color: #002200;">(</span><span style="color: #400080;">NSSet</span><span style="color: #002200;">*</span><span style="color: #002200;">)</span>tou<wbr>ches withEvent<span style="color: #002200;">:</span><span style="color: #002200;">(</span>UIEvent<span style="color: #002200;">*</span><span style="color: #002200;">)</span>event <br /> <span style="color: #002200;">{</span><br />  <span style="color: #a61390;">if</span><span style="color: #002200;">(</span>touches.count <span style="color: #002200;">==</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">)</span><br />   <span style="color: #002200;">{</span>  <br />    <span style="color: #a61390;">if</span><span style="color: #002200;">(</span><span style="color: #002200;">[</span><span style="color: #002200;">[</span>touches anyObject<span style="color: #002200;">]</span> tapCount<span style="color: #002200;">]</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">)</span><br />     <span style="color: #002200;">{</span><br />      <span style="color: #002200;">[</span>self handleDoubleTap<span style="color: #002200;">]</span>;<br />    <span style="color: #002200;">}</span><br />     <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">(</span><span style="color: #002200;">[</span><span style="color: #002200;">[</span>touches anyObject<span style="color: #002200;">]</span> tapCount<span style="color: #002200;">]</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">3</span><span style="color: #002200;">)</span><br />     <span style="color: #002200;">{</span><br />      <span style="color: #002200;">[</span>self handleTripleTap<span style="color: #002200;">]</span>;<br />    <span style="color: #002200;">}</span><br />     <span style="color: #a61390;">else</span><br />    <span style="color: #002200;">{</span><br />      <span style="color: #002200;">[</span>self handleSingleTap<span style="color: #002200;">]</span>; <br />     <span style="color: #002200;">}</span><br />  <span style="color: #002200;">}</span><br /><span style="color: #002200;">}</span></pre></td></tr></tbody></table></div><p style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">If you place a breakpoint inside each of the code blocks for the three tap counts, you will find that in the case where you triple tap, it will break in all three. If you double tap, it will break in both the double tap and single tap and of course if you single tap, it will break in the single tap branch.</p><p style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">In most cases, this is not desirable. You will likely want a clean differentiation between each touch as each tap count will likely mean something different. So how can we fix this? The trick is to use&nbsp;<em>-peformSelector:withObject:<wbr>afterDelay</em>&nbsp;and then canceling the perform action if a new action occurs. Got it?</p><h2>Wait For It&#8230;</h2><p style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">If you call the method directly as we did in the sample code above, there is no way to delay when it runs nor is there a way to cancel it should another tap be received. Both of these things are necessary. If you think about it, waiting to run our&nbsp;<em>-handleSingleTap</em>&nbsp;method until a certain amount of time passes helps make sure it actually was a double tap. If the user taps once and nothing else occurs, we&#8217;re safe to run the&nbsp;<em>-handleSingleTap</em>&nbsp;code. If another tap is received in the mean time, however, we can cancel the action from the first tap. The way we do this is by changing our&nbsp;<em>-touchesEnded:</em>&nbsp;code to something like this:</p><div style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><table><tbody><tr><td style="margin: 0px;"><pre style="white-space: pre-wrap;">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></pre></td><td style="margin: 0px;"><pre style="white-space: pre-wrap;"><span style="color: #002200;">-</span> <span style="color: #002200;">(</span><span style="color: #a61390;">void</span><span style="color: #002200;">)</span>touchesEnded<span style="color: #002200;">:</span><span style="color: #002200;">(</span><span style="color: #400080;">NSSet</span><span style="color: #002200;">*</span><span style="color: #002200;">)</span>tou<wbr>ches withEvent<span style="color: #002200;">:</span><span style="color: #002200;">(</span>UIEvent<span style="color: #002200;">*</span><span style="color: #002200;">)</span>event <br /> <span style="color: #002200;">{</span><br />  <span style="color: #a61390;">if</span><span style="color: #002200;">(</span>touches.count <span style="color: #002200;">==</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">)</span><br />   <span style="color: #002200;">{</span>  <br />    <span style="color: #a61390;">if</span><span style="color: #002200;">(</span><span style="color: #002200;">[</span><span style="color: #002200;">[</span>touches anyObject<span style="color: #002200;">]</span> tapCount<span style="color: #002200;">]</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">)</span><br />     <span style="color: #002200;">{</span><br />      <span style="color: #002200;">[</span>self performSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">(</span>hand<wbr>leDoubleTap<span style="color: #002200;">)</span><br />                  withObject<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><br />                 afterDelay<span style="color: #002200;">:</span><span style="color: #2400d9;">0.35</span><span style="color: #002200;">]</span>; <br />     <span style="color: #002200;">}</span><br />    <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">(</span><span style="color: #002200;">[</span><span style="color: #002200;">[</span>touches anyObject<span style="color: #002200;">]</span> tapCount<span style="color: #002200;">]</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">3</span><span style="color: #002200;">)</span><br />     <span style="color: #002200;">{</span><br />      <span style="color: #002200;">[</span>self handleTripleTap<span style="color: #002200;">]</span>;<br />    <span style="color: #002200;">}</span><br />     <span style="color: #a61390;">else</span><br />    <span style="color: #002200;">{</span><br />      <span style="color: #002200;">[</span>self performSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">(</span>hand<wbr>leSingleTap<span style="color: #002200;">)</span><br />                  withObject<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><br />                 afterDelay<span style="color: #002200;">:</span><span style="color: #2400d9;">0.35</span><span style="color: #002200;">]</span>; <br />     <span style="color: #002200;">}</span><br />  <span style="color: #002200;">}</span><br /><span style="color: #002200;">}</span></pre></td></tr></tbody></table></div><p style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">Notice that we are delaying 350 milliseconds to see if another event occurs. You should also notice that we still call&nbsp;<em>-handleTripleTap</em>&nbsp;directly without using&nbsp;<em>-performSelector:withObject:<wbr>afterDelay</em>. This is because it has now been isolated as a distinct event. If we get a triple tap, we&#8217;re pretty well assured now that a double or single tap event was not actually run as those events will have been cancelled. So how does that work? How do we cancel them?</p><h2>Canceling The Action</h2><p style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">Now that we are waiting around to see if another tap event occurs, we need to override the&nbsp;<em>-touchesBegan:</em>&nbsp;method. It will look something like this:</p><div style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><table><tbody><tr><td style="margin: 0px;"><pre style="white-space: pre-wrap;">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></pre></td><td style="margin: 0px;"><pre style="white-space: pre-wrap;"><span style="color: #002200;">-</span> <span style="color: #002200;">(</span><span style="color: #a61390;">void</span><span style="color: #002200;">)</span>touchesBegan<span style="color: #002200;">:</span><span style="color: #002200;">(</span><span style="color: #400080;">NSSet</span><span style="color: #002200;">*</span><span style="color: #002200;">)</span>tou<wbr>ches withEvent<span style="color: #002200;">:</span><span style="color: #002200;">(</span>UIEvent<span style="color: #002200;">*</span><span style="color: #002200;">)</span>event<br /> <span style="color: #002200;">{</span><br />  <span style="color: #002200;">[</span><span style="color: #400080;">NSObject</span> cancelPreviousPerformRequestsW<wbr>ithTarget<span style="color: #002200;">:</span>self<br />                                            selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">(</span>handleSingl<wbr>eTap<span style="color: #002200;">)</span><br />                                              object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">]</span>;<br />&nbsp;<br />  <span style="color: #002200;">[</span><span style="color: #400080;">NSObject</span> cancelPreviousPerformRequestsW<wbr>ithTarget<span style="color: #002200;">:</span>self<br />                                            selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">(</span>handleDoubl<wbr>eTap<span style="color: #002200;">)</span><br />                                              object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">]</span>;<br /><span style="color: #002200;">}</span></pre></td></tr></tbody></table></div><p style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">The method&nbsp;<em>-<wbr>cancelPreviousPerformRequestsW<wbr>ithTarget:selector:object:</em>&nbsp;is able to determine which action you want to cancel and then cancel it preventing the selectors,&nbsp;<em>-handleSingleTap</em>&nbsp;or&nbsp;<em>-handleDoubleTap</em>&nbsp;from being called&#8211;assuming the second or third taps occurred within the allocated 350 milliseconds. That&#8217;s all there is to it.</p><h2>There *Is* a Catch</h2><p style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">That is all there is to it, however, you have to be careful if you intend to pass parameters to your selectors. If you use a selector that takes a parameter so that you have to call something with&nbsp;<em>-performSelector:withObject:<wbr>afterDelay:</em>&nbsp;passing an object to the second parameter, you will need&nbsp;<em>that</em>&nbsp;object or one identical to it in your call to cancel the action with&nbsp;<em>-<wbr>cancelPreviousPerformRequestsW<wbr>ithTarget:selector:object:</em>. It must be able to evaluate to true when&nbsp;<em>equals</em>&nbsp;is called on the object passed into the&nbsp;<em>object</em>&nbsp;parameter. This can be tricky, but you can overcome it in one of two ways using an ivar:</p><ul style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><li style="margin-left: 15px;"><p>Create an ivar to hold onto the variable that you will use as a parameter to the cancel when you first pass it to the&nbsp;<em>-performSelector:withObject:<wbr>afterDelay:</em>&nbsp;call.</p></li><li style="margin-left: 15px;"><p>Create an ivar to hold onto the variable when you first enter touches ended and call&nbsp;<em>-performSelector:withObject:<wbr>afterDelay</em>&nbsp;passing it nil for the&nbsp;<em>object</em>parameter. Then, grab the ivar when you need it in your handler code. The cancel call can then take nil for its&nbsp;<em>object</em>&nbsp;parameter.</p></li></ul><p style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">These points are crucial if you are intending to pass parameters as the cancel will fail if you try to pass a parameter and it doesn&#8217;t match what you used in your call to&nbsp;<em>-performSelector:withObjecct:<wbr>afterDelay:</em>. The only parameter that doesn&#8217;t matter is the&nbsp;<em>afterDelay:</em>&nbsp;param.</p><h2>Conclusion</h2><p style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">I&#8217;m finding the need to differentiate tap counts more and more often so this post is really as much a way for me to keep a journal of things I need to do frequently as it is to help others figure things out too. I hope it&#8217;s been helpful to you. Until next time.</p><h1>Update</h1><p style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">So, apparently Gesture Recognizers do address this issue. I had looked at them as a possible solution, but ran into the same differentiation problems, hence this blog post. However,&nbsp;<a href="http://twitter.com/aclark" target="_blank" style="color: #1155cc;">Ashley Clark</a>&nbsp;pointed me to the&nbsp;<em><a href="http://developer.apple.com/iphone/library/documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/instm/UIGestureRecognizer/requireGestureRecognizerToFail:" target="_blank" style="color: #1155cc;">-<wbr>requireGestureRecognizerToFail<wbr>:</a></em>&nbsp;method, which apparently enables you to have this cancellation functionality by creating a dependency between recognizers. The code to take advantage of it looks something like this:</p><div style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;"><table><tbody><tr><td style="margin: 0px;"><pre style="white-space: pre-wrap;">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></pre></td><td style="margin: 0px;"><pre style="white-space: pre-wrap;">UITapGestureRecognizer <span style="color: #002200;">*</span>tripleTap <span style="color: #002200;">=</span> <br /><span style="color: #002200;">[</span><span style="color: #002200;">[</span>UITapGestureRecognizer alloc<span style="color: #002200;">]</span><br />  initWithTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">(</span>handleTripleT<wbr>ap<span style="color: #002200;">:</span><span style="color: #002200;">)</span><span style="color: #002200;">]</span>;<br /> &nbsp;<br /><span style="color: #002200;">[</span>tripleTap setNumberOfTapsRequired<span style="color: #002200;">:</span><span style="color: #2400d9;">3</span><span style="color: #002200;">]</span>;<br /> <span style="color: #002200;">[</span><span style="color: #002200;">[</span>self view<span style="color: #002200;">]</span> addGestureRecognizer<span style="color: #002200;">:</span>tripleTap<span style="color: #002200;"><wbr>]</span>;<br /> <span style="color: #002200;">[</span>tripleTap release<span style="color: #002200;">]</span>;<br />&nbsp;<br />UITapGestureRecognizer <span style="color: #002200;">*</span>doubleTap <span style="color: #002200;">=</span> <br /> <span style="color: #002200;">[</span><span style="color: #002200;">[</span>UITapGestureRecognizer alloc<span style="color: #002200;">]</span><br /> initWithTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">(</span>handleDoubleT<wbr>ap<span style="color: #002200;">:</span><span style="color: #002200;">)</span><span style="color: #002200;">]</span>;<br /> &nbsp;<br /><span style="color: #002200;">[</span>doubleTap setNumberOfTapsRequired<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span><span style="color: #002200;">]</span>;<br /> <span style="color: #002200;">[</span>doubleTap requireGestureRecognizerToFail<span style="color: #002200;"><wbr>:</span>tripleTap<span style="color: #002200;">]</span>;<br /><span style="color: #002200;">[</span><span style="color: #002200;">[</span>self view<span style="color: #002200;">]</span> addGestureRecognizer<span style="color: #002200;">:</span>doubleTap<span style="color: #002200;"><wbr>]</span>;<br /> <span style="color: #002200;">[</span>doubleTap release<span style="color: #002200;">]</span>;<br />&nbsp;<br />UITapGestureRecognizer <span style="color: #002200;">*</span>singleTap <span style="color: #002200;">=</span> <br /> <span style="color: #002200;">[</span><span style="color: #002200;">[</span>UITapGestureRecognizer alloc<span style="color: #002200;">]</span><br /> initWithTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">(</span>handleSingleT<wbr>ap<span style="color: #002200;">:</span><span style="color: #002200;">)</span><span style="color: #002200;">]</span>;<br /> &nbsp;<br /><span style="color: #002200;">[</span>singleTap setNumberOfTapsRequired<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">]</span>; <span style="color: #11740a; font-style: italic;">// Unnecessary since it's the default</span><br /> <span style="color: #002200;">[</span>singleTap requireGestureRecognizerToFail<span style="color: #002200;"><wbr>:</span>doubleTap<span style="color: #002200;">]</span>;<br /><span style="color: #002200;">[</span><span style="color: #002200;">[</span>self view<span style="color: #002200;">]</span> addGestureRecognizer<span style="color: #002200;">:</span>singleTap<span style="color: #002200;"><wbr>]</span>;<br /> <span style="color: #002200;">[</span>singleTap release<span style="color: #002200;">]</span>;</pre></td></tr></tbody></table></div><p style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">So, if your project is 3.2 and later, use gesture recognizers. The effect is about the same, but the code is quite a bit cleaner.</p><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">＋＋＋＋＋</span><img src ="http://www.cppblog.com/walkklookk/aggbug/196845.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/walkklookk/" target="_blank">佳为好友</a> 2012-12-30 11:41 <a href="http://www.cppblog.com/walkklookk/archive/2012/12/30/196845.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>原：UIWebView自动换行</title><link>http://www.cppblog.com/walkklookk/archive/2012/12/30/196844.html</link><dc:creator>佳为好友</dc:creator><author>佳为好友</author><pubDate>Sun, 30 Dec 2012 03:40:00 GMT</pubDate><guid>http://www.cppblog.com/walkklookk/archive/2012/12/30/196844.html</guid><wfw:comment>http://www.cppblog.com/walkklookk/comments/196844.html</wfw:comment><comments>http://www.cppblog.com/walkklookk/archive/2012/12/30/196844.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/walkklookk/comments/commentRss/196844.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/walkklookk/services/trackbacks/196844.html</trackback:ping><description><![CDATA[<span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">日期：2011.04.12</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">UIWebView自动换行</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" />这个问题不是UIWebView能解决的，<wbr>需要改动HTML文件。可以修改如下：<br /><br />&lt;div style="word-wrap:break-word; width:20px;"&gt;<wbr>abcdefghijklmnabcdefghijklmnab<wbr>cdefghijklmn111111111&lt;/div&gt;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 控制好width可实现固定宽度，自动换行。<br /><br />＋＋＋＋＋<img src ="http://www.cppblog.com/walkklookk/aggbug/196844.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/walkklookk/" target="_blank">佳为好友</a> 2012-12-30 11:40 <a href="http://www.cppblog.com/walkklookk/archive/2012/12/30/196844.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转：UIImageView不响应手指操作GesutureRecognizer</title><link>http://www.cppblog.com/walkklookk/archive/2012/12/30/196843.html</link><dc:creator>佳为好友</dc:creator><author>佳为好友</author><pubDate>Sun, 30 Dec 2012 03:40:00 GMT</pubDate><guid>http://www.cppblog.com/walkklookk/archive/2012/12/30/196843.html</guid><wfw:comment>http://www.cppblog.com/walkklookk/comments/196843.html</wfw:comment><comments>http://www.cppblog.com/walkklookk/archive/2012/12/30/196843.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/walkklookk/comments/commentRss/196843.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/walkklookk/services/trackbacks/196843.html</trackback:ping><description><![CDATA[<span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">日期：2011.04.13</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">转：</span><a href="http://stackoverflow.com/questions/3907397/gesuturerecognizer-on-uiimageview" target="_blank" style="color: #1155cc; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">http://stackoverflow.com/<wbr>questions/3907397/<wbr>gesuturerecognizer-on-<wbr>uiimageview</a><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><span style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;">Check that userInteractionEnabled is YES on the UIImageView. Then you can add a gesture recognizer.</span><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><br style="color: #222222; font-family: arial, sans-serif; font-size: 14.399999618530273px; line-height: normal; background-color: #ffffff;" /><pre style="white-space: pre-wrap; color: #222222; line-height: normal; background-color: #ffffff;"><code><span style="background-color: #ff6666;">imageView</span><span style="background-color: #ff6666;">.</span><span style="background-color: #ff6666;">userInteractionEnabl<wbr>ed </span><span style="background-color: #ff6666;">=</span><span style="background-color: #ff6666;"> YES</span><span style="background-color: #ff6666;">;</span><br /> UIPinchGestureRecognizer *pgr = [[UIPinchGestureRecognizer alloc] <br /> &nbsp; &nbsp; initWithTarget:self action:@selector(handlePinch:)<wbr>];<br /> pgr.delegate = self;<br /> [imageView addGestureRecognizer:pgr];<br />[pgr release];<br /> :<br />:<br />- (void)handlePinch:(UIPinchGest<wbr>ureRecognizer *)pinchGestureRecognizer<br /> {<br />&nbsp; //handle pinch...<br />}<br /><br />＋＋＋＋＋</code></pre><img src ="http://www.cppblog.com/walkklookk/aggbug/196843.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/walkklookk/" target="_blank">佳为好友</a> 2012-12-30 11:40 <a href="http://www.cppblog.com/walkklookk/archive/2012/12/30/196843.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>