English 中文(简体)
2. 实现母乳喂养 另一门UIImageView完成后的观点
原标题:Make UIImageView animate after another UIImageView has finished

我正试图将卡片交易同化。 目前,我有两张卡,即经销商卡(dCard1)和角色卡(pCard1)。

角色卡应当处理,一旦处理,即应当处理经销商卡。

目前发生的情况是,当我发布交易单时,角色卡将适时使用,但不要等到角色卡进行消化时,交易卡就出现在经销商To所在地。 它不是囚犯。 我是怀着新意,将非常赞赏任何帮助。

-(void) animateHandsDealt: (Hand*) pHand:(Hand*) dHand{
pCard1= [[UIImageView alloc] initWithFrame:CGRectMake(125, 0, 75, 110)];
dCard1= [[UIImageView alloc] initWithFrame:CGRectMake(125, 0, 75, 110)];

CGFloat start = 0;
CGFloat duration = 1;

CGPoint playerTo = CGPointMake(120, 300);
CGPoint dealerTo = CGPointMake(120, 70);

pCard1.image = [UIImage imageNamed:[[pHand.cardArr objectAtIndex:0 ] imagePath]];
[self.view addSubview: pCard1];
[playerImages addObject:pCard1];

CABasicAnimation *move = [CABasicAnimation animationWithKeyPath:@"position" ];
move.fillMode = kCAFillModeBoth;
move.beginTime = start;
[move setToValue:[NSValue valueWithCGPoint:playerTo]];
[move setDuration:duration];
move.removedOnCompletion = FALSE;
[[pCard1 layer] addAnimation:move forKey:@"position"];


dCard1.image = [UIImage imageNamed:@"back-red-75-1.png"];
[self.view addSubview: dCard1];
CABasicAnimation *move2 = [CABasicAnimation animationWithKeyPath:@"position" ];
[move2 setToValue:[NSValue valueWithCGPoint:dealerTo]];
move2.beginTime = start + duration;
[move2 setDuration:duration];
move2.fillMode = kCAFillModeBoth;
move2.removedOnCompletion = FALSE;
[[dCard1 layer] addAnimation:move2 forKey:@"position"];

iii

最佳回答

我没有机会上课(当然),但我认为这很接近于“备份”法。 你认为什么?

- (void)deal {
    // Of course, you d replace these NSString objects with actual card objects...
    NSArray *array = [NSArray arrayWithObjects:@"pCard1", @"dCard1", @"pCard2", @"dCard2", @"pCard3", @"dCard3", nil];
    [self performSelectorOnMainThread:@selector(animateDealWithArray:) withObject:array waitUntilDone:YES];
}
- (void)animateDealWithArray:(NSArray *)array {
    // constants that won t change call to call
    static CGFloat duration = 1;
    static CGSize  cardSize = {75,  110};
    static CGPoint playerTo = {120, 300};
    static CGPoint dealerTo = {120, 70};

    // Seems like you want the card to start at the top of the "deck" whether it s a player card or not
    UIImageView *card = [[UIImageView alloc] initWithFrame:CGRectMake(125, 0, 75, 110)];
    // Figure out if the first object (the one we re currently using) is a player or dealer card
    if ([[array objectAtIndex:0] isKindOfClass:[PlayerCard Class]]) {
        // Player card, so show the "face"
        [card setImage:[UIImage imageNamed:[(PlayerCard *)[array objectAtIndex:0] imagePath]]];
        [UIView animateWithDuration:duration
                         animations:^{
                             [card setFrame:CGRectMake(playerTo.x, playerTo.y, cardSize.width, cardSize.height)];
                         }
                         completion:^(BOOL finished) {
                             [self dealNext:array];
                         }
         ];
    } else {
        // Dealer card, so show the back
        [card setImage:[UIImage imageNamed:@"back-red-75-1.png"]];
        [UIView animateWithDuration:duration
                         animations:^{
                             [card setFrame:CGRectMake(dealerTo.x, dealerTo.y, cardSize.width, cardSize.height)];
                         }
                         completion:^(BOOL finished) {
                             [self dealNext:array];
                         }
         ];
    }
}
- (void)dealNext:(NSArray *)array {
    int count = [array count];
    if (count > 1) {
        NSArray *newArray = [array subarrayWithRange:NSMakeRange(1, count - 1)];
        [self animateDealWithArray:newArray];
    }
}
问题回答

If you re just animating the frame of the view, you can use the much simpler UIView animateWithDuration... methods.

您通过使用业余制:组合:版本。 您可以具体说明完成时的第二次估算:第一次估算的一组。

http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/UIView.html#/apple_ref/doc/uid/TP400016-CH3-SW=





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签