小编don*_*kim的帖子

在iPhone 4上使用陀螺仪补偿罗盘延迟

我一直在试验iPhone 4上的指南针和陀螺仪,并希望得到一些我正在解决的问题的帮助.我想通过使用陀螺仪的数据来弥补指南针的缓慢.

使用CMMotionManager和它的CMDeviceMotionobject(motionManager.deviceMotion),我得到了CMAttitude对象.如果我错了(请),请纠正我,但这是我从CMAttitude对象的yaw属性中推断出来的(我不需要pitch也不是roll为了我的目的):

  • yaw范围从0PI当手机正在指向下方(由所指示的deviceMotion.gravity.z)和逆时针方向摆动,并0-PI顺时针方向摆动时
  • 当设备指向上方时,yaw范围分别为-PIto 0PIto0
  • 和从罗盘数据(我使用locationManager.heading.magneticHeading),我看到罗盘给出了从值0360与值顺时针摆动时增加

好吧,所以一起使用所有这些信息,我能够得到一个我称之为的值horizontal,无论设备是向上还是向下,都会给出值0,360并在设备顺时针摆动时增加(尽管我我在deviceManager.gravity.z周围时仍然遇到麻烦0- yaw价值在这个gravity.z价值上变得非常惊人).

在我看来,我可以使用映射到的计算值"同步" horizontalmagneticHeading值,并在我感觉指南针"赶上"时"同步"该值.horizontalmagneticHeadinghorizontalmagneticHeading

所以我的问题:

  • 我是否在正确的轨道上?
  • CMDeviceMotion是否正确使用陀螺仪数据并且上面列出的假设是正确的?
  • 为什么yaw在 …

iphone ios iphone-4 gyroscope compass-geolocation

30
推荐指数
2
解决办法
1万
查看次数

Iphone facebook连接示例呼叫safari.我不想使用safari

Iphone facebook连接示例呼叫safari.我不想使用safari.如何解决这个问题.

iphone safari facebook

12
推荐指数
2
解决办法
8507
查看次数

使用cocos2d处理CCSprite触摸的最佳实践

大家好.我刚开始研究cocos2d库.我听说如果你习惯于在ActionScript中编程,这是一个很容易进入的库,我发现很多概念确实相似.

我开始查看示例项目(此处链接的示例游戏特别有用),我看到触摸的处理通常不在CCSprite中完成.相反,实例化CCSprites的CCLayer会对触摸事件作出反应,并迭代它创建的精灵以检测触摸了哪个CCSprite(如果有的话).

我想CCSprites处理是否已经打动自己,并调用,通知它已经触及(如果需要).Paddle在/ tests/TouchesTest下找到的类就是这样 - 它自己处理触摸.

所以,我的问题是:对此最佳做法是什么?在中心位置处理触摸并通过子节点迭代以查看触摸的内容是否更好?或者每个孩子应该处理自己的触摸事件?或者没关系?

我希望每个孩子都能处理自己的触摸事件,但我想遵循这方面的最佳实践(如果存在的话).谢谢!

iphone cocos2d-iphone ipad

11
推荐指数
1
解决办法
1万
查看次数

将TTTableViewController(从three20)添加到另一个UIViewController

我遇到了问题three20,我希望有人可以帮助我.

我有一个TTTableViewController类似于示例项目中的TTTwitter应用程序three20使用它的方式.我刚才三种方法我执行:(id)init,(void)createModel,和(id<UITableViewDelegate>)createDelegate.我已经子类TTListDataSourceTTURLRequestModel我的数据.总而言之,这是一个相当简单的用法TTTableViewController,我没有做任何与众不同的事情.

当我将它添加TTTableViewController到后代时UIView,它可以正常工作.它可以完美地加载和显示数据.例如,以下两个工作正常:

FooTableViewController *controller = [[FooTableViewController alloc] init];
controller.view.frame = CGRectMake(288, 20, 480, 1004);
[self.window addSubview:controller.view];
Run Code Online (Sandbox Code Playgroud)

就像这样:

FooTableViewController *controller = [[FooTableViewController alloc] init];
controller.view.frame = CGRectMake(288, 20, 480, 1004);

UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.frame = CGRectMake(0, 0, 768, 1024);
// a bunch of scrollView variable initializations..
[scrollView addSubview:controller.view];
[self.window addSubview:scrollView];
Run Code Online (Sandbox Code Playgroud)

当我尝试添加FooTableViewController(再次,是它的子类 …

iphone uiviewcontroller three20

5
推荐指数
1
解决办法
1872
查看次数

改变CAShapeLayer中的lineWidth

我正在做一个小项目,我想绘制一条bezier曲线.我希望能够改变lineWidth图纸的不同部分.

这就是我所拥有的:

CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame = self.animationLayer.bounds;
pathLayer.bounds = pathRect;
pathLayer.geometryFlipped = YES;
pathLayer.path = path.CGPath;
pathLayer.strokeColor = [[UIColor blackColor] CGColor];
pathLayer.fillColor = nil;
pathLayer.lineWidth = 1.0f;
pathLayer.lineJoin = kCALineJoinBevel;
Run Code Online (Sandbox Code Playgroud)

我该如何改变线条的宽度?一种解决方案可能是使多个UIBezierPaths具有多个CAShapeLayers,但似乎应该有一个更简单,更优雅的解决方案(在指定行指定lineWidth的级别的UIBezierPath某些方面).

谢谢!

iphone core-animation objective-c

4
推荐指数
1
解决办法
5762
查看次数

检测Cocos2d-iphone上是否触摸了特定的精灵

我正在关注Ray的教程,制作一个简单的iPhone游戏(这里:http://goo.gl/fwPi),并决定我想让敌人在被触及时被淘汰.

我最初的方法是在触摸位置生成一个小的CCSprite精灵,然后使用CGRectMake创建一个所述精灵的边界框,以检测敌人的精灵是否被触摸.就像雷与射弹/敌人一样.但是,当然,我这样做的方式不起作用,我无法从这个洞中挖掘自己.

这是相关的代码段.任何帮助表示赞赏:

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    // Choose one of the touches to work with
    UITouch *touch = [touches anyObject];
    CGPoint location = [self convertTouchToNodeSpace: touch];
    location = [[CCDirector sharedDirector] convertToGL:location];
    CCSprite *touchedarea = [CCSprite spriteWithFile:@"Icon-72.png" rect:CGRectMake(location.x, location.y, 2, 2)];
    touchedarea.tag = 2;
    [self addChild:touchedarea];
    [_touchedareas addObject:touchedarea];

}



- (void)update:(ccTime)dt {

    NSMutableArray *touchedareasToDelete = [[NSMutableArray alloc] init];
    for (CCSprite *touchedarea in _touchedareas) {
        CGRect touchedareaRect = CGRectMake(
                                           touchedarea.position.x, 
                                           touchedarea.position.y, 
                                           touchedarea.contentSize.width, 
                                           touchedarea.contentSize.height);

        NSMutableArray *targetsToDelete …

iphone objective-c collision-detection cocos2d-iphone

3
推荐指数
1
解决办法
1万
查看次数