views:

20

answers:

1

Hi there, I'm writing my first app with animations and I'm getting into some troubles. I have a ViewController which creates programmatically a certain number of UIView added as subviews.

Now, when I touch one of these views I'd like to move it in one direction (up, right, down, left) but only if in this direction there isn't another view. The matter is: how can I ask to ViewController if there's another view in one direction? I tried:

// 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];
}

But the NSLog(@"dati ... gives (null). How should I do this?

A: 

I found the solutions putting cells and map in the AppDelegate file. Then I accessed them by a delegate. Thank you.

IssamTP