iPhone多个子视图动画

时间:2010-10-20 16:35:01

标签: iphone animation subview

我正在编写带有动画的第一个应用程序,我遇到了一些麻烦。我有一个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 ...给(null)。 我该怎么做?

1 个答案:

答案 0 :(得分:0)

我发现解决方案将单元格和地图放在AppDelegate文件中。然后我由代表访问它们。谢谢。