分享一个应用iPhone重力感应器程序源代码
在iPhone手机应用程序开发中, 应用iPhone重力感应器方面的教程或例子文章几乎没有,英文方面较为完整的也比较少,今天发现了一个应用重力感应做的游戏的完整的教程(Gravity Tutorial for iPhone),值得借鉴和参考。
总共分为5个部分讲解,下面是各章节的连接地址:
Gravity Tutorial for iPhone Part 1
Gravity Tutorial for iPhone Part 2
Gravity Tutorial for iPhone Part 3
Gravity Tutorial for iPhone part 4
Gravity Tutorial for iPhone, Part 5
另外有发现一个设置iPhone的topbar以及获得重力感应(1.1.x)的代码,可以参考下:
1\屏幕上方的status bar 弄掉,
- (void) applicationDidFinishLaunching: (id) unused
{
[UIHardware _setStatusBarHeight:0.0f];
[self setStatusBarMode:2 orientation:0 duration:0.0f fenceID:0];
//[self setStatusBarMode:4 orientation:90 duration:0.5 fenceID:0 animation: 0];有渐变效果
}
2\获得当前iPhone的感应方向
enum{kFACEUP = 0,kNORMAL = 1,kUPSIDEDOWN = 2,kLANDL = 3,kLANDR = 4,kFACEDOWN = 6};
- (void)deviceOrientationChanged:(id)event {
int orient = [ UIHardware deviceOrientation: YES ];
float animDur = 0.5;
int animType = 0;
// handle status bar transition
switch(orient)
{
case kFACEUP:
case kFACEDOWN:
// do nothing for flat and face down
break;
case kUPSIDEDOWN:
// Disable when upside down, there doesn't seem to be a
// inverted status bar
[self setStatusBarMode:2 orientation:180 duration:animDur fenceID:0 animation: animType];
break;
case kNORMAL:
[self setStatusBarMode:4 orientation:0 duration:animDur fenceID:0 animation: animType];
break;
case kLANDL:
[self setStatusBarMode:4 orientation:90 duration:animDur fenceID:0 animation: animType];
break;
case kLANDR:
[self setStatusBarMode:4 orientation:-90 duration:animDur fenceID:0 animation: animType];
break;
}
// pass orientation event over to top level app view
// [_screenView deviceOrientationChanged: orient];
// no events when started from console
//NSLog(@"orient: %d", orient);
}
Tags: 重力 感应 代码 程序 手机
相关文章:【分享】V2EX安装方法说明:project-babel-v0.6安装步骤 (2009-12-30 10:2:34)
【翻译】在iPhone上使用UITableView开发九宫格视图 (2009-12-28 13:9:16)
【分享】iPhone开发之数据保存 (2009-12-26 10:28:23)
【分享】 iPhone开发经典语录集锦 (2009-12-26 10:22:23)
黑莓手机开发入门:如何为BlackBerry黑莓手机开发应用软件 (2009-11-20 11:51:31)
acer aspire 4520g初步成功安装mac os pc版 (2009-3-10 13:56:51)
手机JAVA软件修改权限 (2008-2-1 15:56:44)
正则表达式30分钟入门教程 (2007-12-27 12:0:11)
订阅
上一篇
下一篇