繁体   English   中英

iPhone多个子视图动画

[英]iPhone multiple subview animation

我正在用动画编写我的第一个应用程序,但遇到了一些麻烦。 我有一个ViewController,它以编程方式创建一定数量的UIView作为子视图添加。

现在,当我触摸其中一个视图时,我想沿一个方向(上,右,下,左)移动它,但前提是在该方向上没有其他视图。 问题是:如何向ViewController询问一个方向是否还有另一个视图? 我试过了:

// In the view controller:
+ (id)sharedInstance {
    static id master = nil;

    @synchronized(self)
    {
        if (master == nil)
        master = [self new];
    }

    return master;
}

...

// In the UIView subclass
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
     [[MyViewController sharedInstance] touchesEnded:touches withEvent:event launchedBy:numero.text];
}

...

// Finally the method
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event launchedBy:(NSString *)launcher 
{
    CGPoint coord = [[cells objectAtIndex:[launcher intValue]] coordinate];

    [NumberView beginAnimations:@"MoveAndStrech" context:nil];
    [NumberView setAnimationDuration:1];
    [NumberView setAnimationBeginsFromCurrentState:YES];

    if([touches count] == 1) {
        if ( ![map objectForKey:[NSString stringWithFormat:@"%d+%d",coord.x+64,coord.y]] ) {
            NSNumber *isAvailable = [NSNumber numberWithBool:NO];
            [map setValue:isAvailable forKey:[NSString stringWithFormat:@"%d+%d",coord.x,coord.y]];
            NSLog(@"Dati: %@ all'indice: %d",[cells objectAtIndex:[launcher intValue]-1], [launcher intValue]-1);
            [[cells objectAtIndex:[launcher intValue]] setCenter:CGPointMake((coord.x+64)/2, coord.y)]/* = CGPointMake((coord.x+64)/2, coord.y)*/;
            isAvailable = [NSNumber numberWithBool:YES];
            [map setValue:isAvailable forKey:[NSString stringWithFormat:@"%d+%d",coord.x+64,coord.y]];
        }
    }
    [NumberView commitAnimations];
}

但是NSLog(@“ dati ...给(空)。我应该怎么做?

我找到了将单元格和地图放入AppDelegate文件中的解决方案。 然后我由一名代表访问了它们。 谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM