小编Dam*_*anD的帖子

Sprite Kit bodyAtPoint和bodyInRect返回错误的值?

我创建了一个非常简单的示例代码,只有一个场景,一个精灵节点20x20px,屏幕上的点0.0.当我调用scene.physicsWorld bodyAtPoint它时,即使在例如34x34点,也会返回此节点.但在35x35点它会返回null.所以基本上所有从0px到34px的点都返回此节点,从35px开始,它不再返回它.任何想法可能是什么原因,如果精灵明显以20px 20px结束?可以看到相同的行为bodyInRect.

以下是示例代码:

-(id)initWithSize:(CGSize)size {    
if (self = [super initWithSize:size]) {
    /* Setup your scene here */

    self.backgroundColor = [SKColor colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0];
    self.physicsWorld.gravity = CGVectorMake(0, 0);

    SKSpriteNode *node = [[SKSpriteNode alloc] initWithColor:[UIColor whiteColor] size:CGSizeMake(20, 20)];
    node.position = CGPointMake(10, 10);

    node.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(20, 20)];
    [self addChild:node];

}
return self;
}

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

for (UITouch *touch in touches) {
    CGPoint location = [touch locationInNode:self];
    if([self.physicsWorld bodyAtPoint:location])
    {
        NSLog(@"Detected at …
Run Code Online (Sandbox Code Playgroud)

ios ios7 sprite-kit skphysicsbody sknode

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

UIPresentationController preferredContentSize 更新动画

所以我有一个非常基本的 UIPresentationController,它基本上以屏幕为中心显示 contentView,它的大小由视图控制器 preferredContentSize 决定。(它非常类似于以 FormSheet 形式呈现的常规模式视图控制器)。

我想要实现的是能够动态更新此视图控制器视图的大小,只需更改它的 preferredContentSize。

当我设置 preferredContentSize 时,我的 UIPresentationController 子类在以下位置接收有关它的信息:

-(void)preferredContentSizeDidChangeForChildContentContainer:(id<UIContentContainer>)container
Run Code Online (Sandbox Code Playgroud)

但是我如何从这里用动画调整视图框架的大小?如果我只是打电话:

-(void)preferredContentSizeDidChangeForChildContentContainer:(id<UIContentContainer>)container
{
    [UIView animateWithDuration:1.0 animations:^{
        self.presentedView.frame = [self frameOfPresentedViewInContainerView];
    } completion:nil]; 
}
Run Code Online (Sandbox Code Playgroud)

立即被调用 containerViewWillLayoutSubviews 并且框架在没有动画的情况下被改变。

-(void)containerViewWillLayoutSubviews
{
    self.presentedView.frame = [self frameOfPresentedViewInContainerView];
}
Run Code Online (Sandbox Code Playgroud)

请帮我找到一种方法,用动画调整它的大小。这一定是可能的,因为它会随着动画调整大小,例如在发生旋转时。

animation uikit ios uipresentationcontroller

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