<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iPhoneGeek 爱疯极客 &#187; 源代码</title>
	<atom:link href="http://www.iphone-geek.cn/tag/%e6%ba%90%e4%bb%a3%e7%a0%81/feed" rel="self" type="application/rss+xml" />
	<link>http://www.iphone-geek.cn</link>
	<description>iPhone 新闻，编程，技巧与提示，代码，教程</description>
	<lastBuildDate>Thu, 08 Dec 2011 01:18:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>开始学习iphone编程之六 &#8211; 简单示例代码</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%bc%80%e5%a7%8b%e5%ad%a6%e4%b9%a0iphone%e7%bc%96%e7%a8%8b%e4%b9%8b%e5%85%ad-%e7%ae%80%e5%8d%95%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%bc%80%e5%a7%8b%e5%ad%a6%e4%b9%a0iphone%e7%bc%96%e7%a8%8b%e4%b9%8b%e5%85%ad-%e7%ae%80%e5%8d%95%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81#comments</comments>
		<pubDate>Mon, 18 Jan 2010 09:53:24 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[用户界面]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[源代码]]></category>
		<category><![CDATA[代码片段]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=788</guid>
		<description><![CDATA[下面有一些iPhone OS 3.0的范例代码。这些代码都是没有使用Interface Builder的。作为初学者，用这种方法可以更清晰的知道程序是怎样创建用户接口的。

Window， View 和 Control
最基本的iPhone组件。
第一个程序

演示了：


设置项目并通过程序配置用户界面。
创建一个自定义类实现UIApplicationDelegate 协议。
在 main.m中设置delegate。 
创建一个UIWindow 并显示于屏幕上。
为主窗口增加一个子视图。

FirstApp源代码下载

可编辑详情视窗

提供一个文本域和一个按钮。
演示了：

使用CGRect 结构来确定子视图大小和定位。
创建一个诸如UITextField 和 UIButton的UIControl子类 。
实现处理用户触摸动作的方法。
在用户触发事件时修改 UITextField的值。
动态修改 UILabel的值。


EditableDetailView源码下载

视图动画



提供一个文本域和按钮。
演示了：

创建一个自定义 UIView 子类，它提供了自定义的动画行为。
启动 CAAnimation 。
为UIView增加一个或多个CAAffineTransform。
设置诸如动画曲线，时长和重复次数等属性。


AnimatingAView1.1源码下载

Table Views

一系列示例展示了表格视图以及导航控制器。
简单TableView


包括一个列表式UITableView，它显示了一个数组中的字符串。

演示了：

创建一个自定义UITableViewController子类。 
实现UITableViewDataSource协议要求的方法并为UITableView赋值。 
创建一个UITableViewCell并赋值。
在表格视图的各行以不同字体属性显示不同的字符串。


SimpleTableView1.1源码下载

带导航条的TableView

包括一个列表式UITableView，当用户轻触某行时进入分组式表格视图。
演示了：

通过 UINavigationController 提供不同屏幕间的导航。
实现UITableViewDelegate协议的tableViewDidSelectRowAtIndexPath: 方法来处理行选择，进入另一个视图。
通过设置字体等来控制UITableViewCell 的外观。
需要时自动加载代表 UITableView 的数据。
使用分组式 UITableView 来表示一个详情视图。


TableViewWithNavigation1.1源码下载

可编辑TableView


具有一个列表式UITableView，允许添加，删除以及行的重新排序，并允许进入包括了可编辑字段的分组式表格视图对属性进行编辑。

演示了：

创建了一个包括可编辑UITextField的自定义UITableViewCell子类。
使用UINavigationController添加新的条目到 UITableView。 
创建并改变UIImage 的大小来设置表格单元的图像。
管理表格视图的键盘，通过程序使其出现，改变键盘类型以及消失。
管理导航控制器UINavigationBar上的按钮。


EditableTableView1.1源码下载

带有文件支持的TableView

类似于可编辑TableView，但增加一些特性，包括文件支持。

演示了：

创建一个包括UITextField的自定义UITableViewCell 子类，它允许表格单元可编辑。
使用UINavigationController 增加新条目到 UITableView。 
创建并改变UIImage的大小从而设置表格单元的图像。
管理表格视图的键盘，通过程序使其出现，改变键盘类型以及消失。
管理导航控制器UINavigationBar上的按钮。


TableViewWithFilePersistence1.1源码下载

]]></description>
			<content:encoded><![CDATA[<p>下面有一些iPhone OS 3.0的范例代码。这些代码都是没有使用Interface Builder的。作为初学者，用这种方法可以更清晰的知道程序是怎样创建用户接口的。</p>
<p><span id="more-788"></span></p>
<h3 style="margin-top: 24px;">Window， View 和 Control</h3>
<p>最基本的iPhone组件。</p>
<h4>第一个程序</h4>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/FirstApp.png"><img class="alignnone size-full wp-image-790" title="FirstApp" src="http://www.iphone-geek.cn/wp-content/uploads/2010/01/FirstApp.png" alt="FirstApp" width="257" height="375" /></a></p>
<p>演示了：</p>
<p><!-- ul.nested li { padding: 5px; line-height: 18px; } --></p>
<ul>
<li>设置项目并通过程序配置用户界面。</li>
<li>创建一个自定义类实现UIApplicationDelegate 协议。</li>
<li>在 main.m中设置delegate。 </li>
<li>创建一个UIWindow 并显示于屏幕上。</li>
<li>为主窗口增加一个子视图。</li>
</ul>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/FirstApp.zip">FirstApp源代码下载</a></p>
<p><br class="spacer_" /></p>
<h4>可编辑详情视窗</h4>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/EditableDetailView.png"><img class="alignnone size-full wp-image-791" title="EditableDetailView" src="http://www.iphone-geek.cn/wp-content/uploads/2010/01/EditableDetailView.png" alt="EditableDetailView" width="256" height="375" /></a></p>
<p>提供一个文本域和一个按钮。</p>
<p>演示了：</p>
<ul>
<li>使用CGRect 结构来确定子视图大小和定位。</li>
<li>创建一个诸如UITextField 和 UIButton的UIControl子类 。</li>
<li>实现处理用户触摸动作的方法。</li>
<li>在用户触发事件时修改 UITextField的值。</li>
<li>动态修改 UILabel的值。</li>
</ul>
<p><br class="spacer_" /></p>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/EditableDetailView.zip">EditableDetailView源码下载</a></p>
<p><br class="spacer_" /></p>
<h4>视图动画</p>
<p><br class="spacer_" /></p>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/AnimatingAView1.png"><img class="alignnone size-full wp-image-795" title="AnimatingAView" src="http://www.iphone-geek.cn/wp-content/uploads/2010/01/AnimatingAView1.png" alt="AnimatingAView" width="257" height="375" /></a></p>
</h4>
<p>提供一个文本域和按钮。</p>
<p>演示了：</p>
<ul>
<li>创建一个自定义 UIView 子类，它提供了自定义的动画行为。</li>
<li>启动 CAAnimation 。</li>
<li>为UIView增加一个或多个CAAffineTransform。</li>
<li>设置诸如动画曲线，时长和重复次数等属性。</li>
</ul>
<p><br class="spacer_" /></p>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/AnimatingAView1.1.zip">AnimatingAView1.1源码下载</a></p>
<p><br class="spacer_" /></p>
<h3>Table Views</h3>
<p><br class="spacer_" /></p>
<p>一系列示例展示了表格视图以及导航控制器。</p>
<h4>简单TableView</h4>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/SimpleTableView.png"><img class="alignnone size-full wp-image-802" title="SimpleTableView" src="http://www.iphone-geek.cn/wp-content/uploads/2010/01/SimpleTableView.png" alt="SimpleTableView" width="258" height="379" /></a></p>
<p><br class="spacer_" /></p>
<p>包括一个列表式UITableView，它显示了一个数组中的字符串。</p>
<p><br class="spacer_" /></p>
<p>演示了：</p>
<ul>
<li>创建一个自定义UITableViewController子类。 </li>
<li>实现UITableViewDataSource协议要求的方法并为UITableView赋值。 </li>
<li>创建一个UITableViewCell并赋值。</li>
<li>在表格视图的各行以不同字体属性显示不同的字符串。</li>
</ul>
<p><br class="spacer_" /></p>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/SimpleTableView1.1.zip">SimpleTableView1.1源码下载</a></p>
<p><br class="spacer_" /></p>
<h4>带导航条的TableView</h4>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/TableViewWithNavigation.png"><img class="alignnone size-full wp-image-804" title="TableViewWithNavigation" src="http://www.iphone-geek.cn/wp-content/uploads/2010/01/TableViewWithNavigation.png" alt="TableViewWithNavigation" width="256" height="376" /></a></p>
<p>包括一个列表式UITableView，当用户轻触某行时进入分组式表格视图。</p>
<p>演示了：</p>
<ul>
<li>通过 UINavigationController 提供不同屏幕间的导航。</li>
<li>实现UITableViewDelegate协议的tableViewDidSelectRowAtIndexPath: 方法来处理行选择，进入另一个视图。</li>
<li>通过设置字体等来控制UITableViewCell 的外观。</li>
<li>需要时自动加载代表 UITableView 的数据。</li>
<li>使用分组式 UITableView 来表示一个详情视图。</li>
</ul>
<p><br class="spacer_" /></p>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/TableViewWithNavigation1.1.zip">TableViewWithNavigation1.1源码下载</a></p>
<p><br class="spacer_" /></p>
<h4>可编辑TableView</h4>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/EditableTableView.png"><img class="alignnone size-full wp-image-806" title="EditableTableView" src="http://www.iphone-geek.cn/wp-content/uploads/2010/01/EditableTableView.png" alt="EditableTableView" width="257" height="375" /></a></p>
<p><br class="spacer_" /></p>
<p>具有一个列表式UITableView，允许添加，删除以及行的重新排序，并允许进入包括了可编辑字段的分组式表格视图对属性进行编辑。</p>
<p><br class="spacer_" /></p>
<p>演示了：</p>
<ul>
<li>创建了一个包括可编辑UITextField的自定义UITableViewCell子类。</li>
<li>使用UINavigationController添加新的条目到 UITableView。 </li>
<li>创建并改变UIImage 的大小来设置表格单元的图像。</li>
<li>管理表格视图的键盘，通过程序使其出现，改变键盘类型以及消失。</li>
<li>管理导航控制器UINavigationBar上的按钮。</li>
</ul>
<p><br class="spacer_" /></p>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/EditableTableView1.1.zip">EditableTableView1.1源码下载</a></p>
<p><br class="spacer_" /></p>
<h4>带有文件支持的TableView</h4>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/TableViewWithFilePersistence.png"><img class="alignnone size-full wp-image-810" title="TableViewWithFilePersistence" src="http://www.iphone-geek.cn/wp-content/uploads/2010/01/TableViewWithFilePersistence.png" alt="TableViewWithFilePersistence" width="256" height="376" /></a></p>
<p>类似于可编辑TableView，但增加一些特性，包括文件支持。</p>
<p><br class="spacer_" /></p>
<p>演示了：</p>
<ul>
<li>创建一个包括UITextField的自定义UITableViewCell 子类，它允许表格单元可编辑。</li>
<li>使用UINavigationController 增加新条目到 UITableView。 </li>
<li>创建并改变UIImage的大小从而设置表格单元的图像。</li>
<li>管理表格视图的键盘，通过程序使其出现，改变键盘类型以及消失。</li>
<li>管理导航控制器UINavigationBar上的按钮。</li>
</ul>
<p><br class="spacer_" /></p>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/01/TableViewWithFilePersistence1.1.zip">TableViewWithFilePersistence1.1源码下载</a></p>
<p><br class="spacer_" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%bc%80%e5%a7%8b%e5%ad%a6%e4%b9%a0iphone%e7%bc%96%e7%a8%8b%e4%b9%8b%e5%85%ad-%e7%ae%80%e5%8d%95%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Poco C++ for iPhone之一 &#8211; 编译</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/poco-c-for-iphone%e4%b9%8b%e4%b8%80-%e7%bc%96%e8%af%91</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/poco-c-for-iphone%e4%b9%8b%e4%b8%80-%e7%bc%96%e8%af%91#comments</comments>
		<pubDate>Tue, 29 Dec 2009 02:39:58 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[基础]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[跨平台]]></category>
		<category><![CDATA[开源项目]]></category>
		<category><![CDATA[源代码]]></category>
		<category><![CDATA[代码片段]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=554</guid>
		<description><![CDATA[Poco C++是一个强大的跨平台C++库，你可以在iPhone程序中使用它，如果：

你打算使你的程序跨平台。
你喜欢使用C++或希望使用Poco C++中的功能如：XML，Zip等。

&#160;
目前，最新Poco C++版本为1.3.6P1，根据文档，它可以编译为iPhone静态库。但是我试用了一下，无法使用在iPhone Xcode项目中链接，不知何故。所以我自己创建了下列Xcode项目：

Poco Foundation
Poco Util
Poco Net
Poco XML
Poco Zip

&#160;
另外，由于Crypto，Data，NetSSL_OpenSSL库需要外部库而且目前我不需要使用，所以没有包括。另外我增加了一个目录iPhoneSamples，它目前包括了一个示例程序HelloPoco，演示了怎样在iPhone项目中使用Poco C++库（此演示程序十分简单，它调用Poco中的UUID功能，产生一个UUID，显示与屏幕上）。下面是包括了此展示程序以及各Xcode文件的Poco包的下载：
&#160;
poco-1.3.6p1
]]></description>
			<content:encoded><![CDATA[<p>Poco C++是一个强大的跨平台C++库，你可以在iPhone程序中使用它，如果：</p>
<ol>
<li>你打算使你的程序跨平台。</li>
<li>你喜欢使用C++或希望使用Poco C++中的功能如：XML，Zip等。</li>
</ol>
<p>&nbsp;</p>
<p>目前，最新Poco C++版本为1.3.6P1，根据文档，它可以编译为iPhone静态库。但是我试用了一下，无法使用在iPhone Xcode项目中链接，不知何故。所以我自己创建了下列Xcode项目：</p>
<ul>
<li>Poco Foundation</li>
<li>Poco Util</li>
<li>Poco Net</li>
<li>Poco XML</li>
<li>Poco Zip</li>
</ul>
<p>&nbsp;</p>
<p>另外，由于Crypto，Data，NetSSL_OpenSSL库需要外部库而且目前我不需要使用，所以没有包括。另外我增加了一个目录iPhoneSamples，它目前包括了一个示例程序HelloPoco，演示了怎样在iPhone项目中使用Poco C++库（此演示程序十分简单，它调用Poco中的UUID功能，产生一个UUID，显示与屏幕上）。下面是包括了此展示程序以及各Xcode文件的Poco包的下载：</p>
<p>&nbsp;</p>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2009/12/poco-1.3.6.zip">poco-1.3.6p1</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/poco-c-for-iphone%e4%b9%8b%e4%b8%80-%e7%bc%96%e8%af%91/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>跨平台代码分享之二 &#8211; 定时器</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e8%b7%a8%e5%b9%b3%e5%8f%b0%e4%bb%a3%e7%a0%81%e5%88%86%e4%ba%ab%e4%b9%8b%e4%ba%8c-%e5%ae%9a%e6%97%b6%e5%99%a8</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e8%b7%a8%e5%b9%b3%e5%8f%b0%e4%bb%a3%e7%a0%81%e5%88%86%e4%ba%ab%e4%b9%8b%e4%ba%8c-%e5%ae%9a%e6%97%b6%e5%99%a8#comments</comments>
		<pubDate>Fri, 20 Nov 2009 03:58:03 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[跨平台]]></category>
		<category><![CDATA[定时器]]></category>
		<category><![CDATA[源代码]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=278</guid>
		<description><![CDATA[定时器的应用实在是太广了，从普通应用程序到游戏，大部分程序都会用到定时器。如果你打算让你的应用程序跨越平台的限制，一个跨平台的定时器是必不可少的。上一次，我给大家分享了一段有关线程的代码。实际上，定时器的是以线程为基础的，在这里我仍然是使用pthread，当然大家可以直接继承我的utils::CThread类。
&#160;

timer.h：
&#160;
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667/*
&#160;* &#160;timer.h
&#160;* &#160;utils
&#160;*
&#160;* &#160;Created by Bagusflyer on 09-6-2.
&#160;* &#160;Copyright 2009 www.iphone-geek.cn. All rights reserved.
&#160;*
&#160;*/

#ifndef _IPHONEGEEK_UTILS_TIMER_H_
#define _IPHONEGEEK_UTILS_TIMER_H_

#include &#60;pthread.h&#62;

namespace utils
&#123;
&#160; &#160; 
&#160; &#160; class CTimer;
&#160; &#160; 
&#160; &#160; class CTimerCallbackInterface
&#160; &#160; &#123;
&#160; &#160; public:
&#160; &#160; &#160; &#160; virtual void onTimer&#40;const CTimer* timer&#41; = 0;
&#160; &#160; &#125;;

&#160; &#160; class CTimer 
&#160; &#160; &#123;
&#160; &#160; public: &#160; &#160; 
&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>定时器的应用实在是太广了，从普通应用程序到游戏，大部分程序都会用到定时器。如果你打算让你的应用程序跨越平台的限制，一个跨平台的定时器是必不可少的。上一次，我给大家分享了一段有关线程的代码。实际上，定时器的是以线程为基础的，在这里我仍然是使用pthread，当然大家可以直接继承我的utils::CThread类。</p>
<p>&nbsp;</p>
<p><span id="more-278"></span></p>
<h2>timer.h：</h2>
<p>&nbsp;</p>
<div class="codecolorer-container cpp mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>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 />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0000; font-style: italic;">/*<br />
&nbsp;* &nbsp;timer.h<br />
&nbsp;* &nbsp;utils<br />
&nbsp;*<br />
&nbsp;* &nbsp;Created by Bagusflyer on 09-6-2.<br />
&nbsp;* &nbsp;Copyright 2009 www.iphone-geek.cn. All rights reserved.<br />
&nbsp;*<br />
&nbsp;*/</span><br />
<br />
<span style="color: #339900;">#ifndef _IPHONEGEEK_UTILS_TIMER_H_</span><br />
<span style="color: #339900;">#define _IPHONEGEEK_UTILS_TIMER_H_</span><br />
<br />
<span style="color: #339900;">#include &lt;pthread.h&gt;</span><br />
<br />
<span style="color: #0000ff;">namespace</span> utils<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">class</span> CTimer<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">class</span> CTimerCallbackInterface<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> onTimer<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> CTimer<span style="color: #000040;">*</span> timer<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">class</span> CTimer <br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span> &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">enum</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TIMER_STOP&nbsp; <span style="color: #000080;">=</span> 0,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TIMER_RUN,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TIMER_PAUSE <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span> TimerState<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; CTimer<span style="color: #008000;">&#40;</span>CTimerCallbackInterface<span style="color: #000040;">*</span> callback,<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> interval,<span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> userData,<span style="color: #0000ff;">bool</span> repeat <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">void</span> resume<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">void</span> pause<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">void</span> stop<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>&nbsp; &nbsp; <span style="color: #666666;">// calling this will destroy CTimer object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> interval<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> m_ulInterval<span style="color: #008080;">;</span>&nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> userData<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> m_pUserData<span style="color: #008080;">;</span> &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">bool</span> isRepeat<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> m_bRepeat<span style="color: #008080;">;</span> &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CTimerCallbackInterface<span style="color: #000040;">*</span> callback<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span> &nbsp; <span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> m_pCallback<span style="color: #008080;">;</span> &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TimerState state<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> m_state<span style="color: #008080;">;</span> &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">private</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CTimerCallbackInterface<span style="color: #000040;">*</span>&nbsp; &nbsp; m_pCallback<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_pUserData<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">bool</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_bRepeat<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_ulInterval<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pthread_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_thread<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TimerState&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_state<span style="color: #008080;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">friend</span> <span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> onRun<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> ptr<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">void</span> start<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; ~CTimer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #339900;">#endif // _IPHONEGEEK_UTILS_TIMER_H_</span></div></td></tr></tbody></table></div>
<p>&nbsp;</p>
<h2>timer.cpp:</h2>
<p>&nbsp;</p>
<div class="codecolorer-container cpp mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>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 />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0000; font-style: italic;">/*<br />
&nbsp;* &nbsp;Timer.cpp<br />
&nbsp;* &nbsp;utils<br />
&nbsp;*<br />
&nbsp;* &nbsp;Created by Bagusflyer on 09-6-2.<br />
&nbsp;* &nbsp;Copyright 2009 www.iphone-geek.cn. All rights reserved.<br />
&nbsp;*<br />
&nbsp;*/</span><br />
<br />
<span style="color: #339900;">#include &quot;utils/timer.h&quot;</span><br />
<span style="color: #339900;">#include &lt;assert.h&gt;</span><br />
<br />
<span style="color: #0000ff;">namespace</span> utils<br />
<span style="color: #008000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666;">// main loop for the timer thread</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> onRun<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> ptr<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span> &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">bool</span> run <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; CTimer<span style="color: #000040;">*</span> theTimer <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>CTimer<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>ptr<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span> run <span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">switch</span> <span style="color: #008000;">&#40;</span> theTimer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>state<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">case</span> CTimer<span style="color: #008080;">::</span><span style="color: #007788;">TIMER_PAUSE</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msleep<span style="color: #008000;">&#40;</span>50<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">case</span> CTimer<span style="color: #008080;">::</span><span style="color: #007788;">TIMER_RUN</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CTimerCallbackInterface<span style="color: #000040;">*</span> callback <span style="color: #000080;">=</span> theTimer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>callback<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; callback<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>onTimer<span style="color: #008000;">&#40;</span>theTimer<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> <span style="color: #000040;">!</span>theTimer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>isRepeat<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; theTimer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>stop<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msleep<span style="color: #008000;">&#40;</span>theTimer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>interval<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">case</span> CTimer<span style="color: #008080;">::</span><span style="color: #007788;">TIMER_STOP</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; run <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>&nbsp; &nbsp; <span style="color: #666666;">// exit the main loop</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">delete</span> theTimer<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">NULL</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; CTimer<span style="color: #008080;">::</span><span style="color: #007788;">CTimer</span><span style="color: #008000;">&#40;</span>CTimerCallbackInterface<span style="color: #000040;">*</span> callback,<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> interval,<span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> userData,<span style="color: #0000ff;">bool</span> repeat<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">:</span> m_pCallback<span style="color: #008000;">&#40;</span>callback<span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_pUserData<span style="color: #008000;">&#40;</span>userData<span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_bRepeat<span style="color: #008000;">&#40;</span>repeat<span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_ulInterval<span style="color: #008000;">&#40;</span>interval<span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_state<span style="color: #008000;">&#40;</span>TIMER_PAUSE<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span>callback<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">// create a thread</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pthread_create<span style="color: #008000;">&#40;</span> <span style="color: #000040;">&amp;</span>m_thread,<span style="color: #0000ff;">NULL</span>,onRun, <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #0000dd;">this</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">// TODO: error check</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; start<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; CTimer<span style="color: #008080;">::</span>~CTimer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pthread_join<span style="color: #008000;">&#40;</span>m_thread, <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">void</span> CTimer<span style="color: #008080;">::</span><span style="color: #007788;">start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; m_state <span style="color: #000080;">=</span> TIMER_RUN<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">void</span> CTimer<span style="color: #008080;">::</span><span style="color: #007788;">resume</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">// TODO: to be done</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; m_state <span style="color: #000080;">=</span> TIMER_RUN<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">void</span> CTimer<span style="color: #008080;">::</span><span style="color: #007788;">stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; m_state <span style="color: #000080;">=</span> TIMER_STOP<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">void</span> CTimer<span style="color: #008080;">::</span><span style="color: #007788;">pause</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">// TODO: to be implemented</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; m_state <span style="color: #000080;">=</span> TIMER_PAUSE<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>&nbsp;</p>
<p>注意：msleep在<a href="%E7%BC%96%E7%A8%8B/%E8%B7%A8%E5%B9%B3%E5%8F%B0%E4%BB%A3%E7%A0%81%E5%88%86%E4%BA%AB-%E7%BA%BF%E7%A8%8B">跨平台代码分享系列之一</a>中有说明。</p>
<p>&nbsp;</p>
<h2>使用方法:</h2>
<p>&nbsp;</p>
<div class="codecolorer-container cpp mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>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 />26<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">// .h文件中</span><br />
<span style="color: #0000ff;">class</span> MyApp<span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> utils<span style="color: #008080;">::</span><span style="color: #007788;">CTimerCallbackInterface</span> &nbsp;<span style="color: #666666;">// 继承CTimerCallbackInterface</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">void</span> onTimer<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> utils<span style="color: #008080;">::</span><span style="color: #007788;">CTimer</span><span style="color: #000040;">*</span> timer<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// 实现onTimer</span><br />
<br />
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">// .cpp 文件中某处</span><br />
<span style="color: #666666;">// 参数1 - 指向CTimerCallbackInterface</span><br />
<span style="color: #666666;">// 参数2 - 定时器分辨率，以ms为单位，此例为10ms</span><br />
<span style="color: #666666;">// 参数3 - 数据指针，用来传递数据到定时器回调中</span><br />
<span style="color: #666666;">// 参数4 - 是否循环触发</span><br />
utils<span style="color: #008080;">::</span><span style="color: #007788;">CTimer</span><span style="color: #000040;">*</span> timer <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> utils<span style="color: #008080;">::</span><span style="color: #007788;">CTimer</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">this</span>,10,data,<span style="color: #0000ff;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <br />
<br />
<span style="color: #666666;">// 回调</span><br />
<span style="color: #0000ff;">void</span> MyApp<span style="color: #008080;">::</span><span style="color: #007788;">onTimer</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> utils<span style="color: #008080;">::</span><span style="color: #007788;">CTimer</span><span style="color: #000040;">*</span> theTimer<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666;">// 指向你想要的功能</span><br />
&nbsp; &nbsp; <span style="color: #666666;">// 你可以使用下面方法获取来自于定时器的数据</span><br />
&nbsp; &nbsp; UserData<span style="color: #000040;">*</span> data <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>UserData<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>theTimer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>userData<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #666666;">// 释放</span><br />
<span style="color: #666666;">// 记住一定要调用stop，来删除创建的定时器</span><br />
timer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>stop<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></td></tr></tbody></table></div>
<p>&nbsp;</p>
<p>下次的题目是跨平台xml解析。有什么问题，建议，希望大家给点回复！你们的支持是我坚持下去的动力，谢谢！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e8%b7%a8%e5%b9%b3%e5%8f%b0%e4%bb%a3%e7%a0%81%e5%88%86%e4%ba%ab%e4%b9%8b%e4%ba%8c-%e5%ae%9a%e6%97%b6%e5%99%a8/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>一款App Store上架游戏的源代码</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e4%b8%80%e6%ac%beapp-store%e4%b8%8a%e6%9e%b6%e6%b8%b8%e6%88%8f%e7%9a%84%e6%ba%90%e4%bb%a3%e7%a0%81</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e4%b8%80%e6%ac%beapp-store%e4%b8%8a%e6%9e%b6%e6%b8%b8%e6%88%8f%e7%9a%84%e6%ba%90%e4%bb%a3%e7%a0%81#comments</comments>
		<pubDate>Fri, 13 Nov 2009 02:43:35 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[开源项目]]></category>
		<category><![CDATA[游戏]]></category>
		<category><![CDATA[源代码]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=223</guid>
		<description><![CDATA[发现一款App Store上架游戏的源代码，游戏名为Tweejump。它是以Cocos2D为引擎的。想学习开源Cocos2D引擎的朋友可以参考下。

源码下载地址在Github，直接按“Download&#8221;就可以下载了。
]]></description>
			<content:encoded><![CDATA[<p>发现一款App Store上架游戏的源代码，游戏名为<a href="http://iplayful.com/tweejump/">Tweejump</a>。它是以Cocos2D为引擎的。想学习开源Cocos2D引擎的朋友可以参考下。</p>
<p><img alt="" src="http://iplayful.com/tweejump/tweejump.jpg" title="tweejump" class="alignnone" width="318" height="459" /></p>
<p>源码下载地址在<a href="http://github.com/haqu/tweejump">Github</a>，直接按“Download&#8221;就可以下载了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e4%b8%80%e6%ac%beapp-store%e4%b8%8a%e6%9e%b6%e6%b8%b8%e6%88%8f%e7%9a%84%e6%ba%90%e4%bb%a3%e7%a0%81/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

