【问题标题】:iPhone multiple subview animationiPhone 多子视图动画
【发布时间】:2010-10-20 16:35:00
【问题描述】:

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

【问题讨论】:

    标签: iphone animation subview


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-18
      • 1970-01-01
      相关资源
      最近更新 更多