-2

我很新,我正在展示 5 张牌,一张是 Ace。我想显示 1 秒(在开始时设置图像)并立即隐藏它(将图像更改为其他图像)。怎么做 ?如何获取具有 Ace 的按钮的 id ?我认为它必须在 - (void)viewDidLoad 方法中完成,或者我弄错了?

4

1 回答 1

0

最好的方法是创建带有保留标题的 UIButton,与卡片相同。例子 :

// I hope you are maintaining an array for the cards
    NSArray *arrCard = [[NSArray alloc]initWithObjects:@"Ace",@"1" ............., nil];

UIButton *btnCard = [[UIButton alloc]init];
     btnCard = [UIButton buttonWithType:UIButtonTypeCustom];
     [btnCard setBackgroundColor:[UIColor clearColor]];
     [btnCard setFrame:CGRectMake(0,100,40,80)]; // Keep this portion in the loop.
   [btnCard setTitle:[NSString stringWithFormat:@"%@", [arrCard objectAtIndex:i] forState:UIControlStateReserved];

// For image of the card
    [btnCard setImage:[UIImage imageNamed:[arrImages objectAtIndex:i]] forState:UIControlStateNormal];

     [self.view addSubview:btnCard];

    if ( [[btnCard titleForState:UIControlStateReserved] isEqualToString: @"Ace"])
    {
    // To keep it displayed for one second
              [UIView animateWithDuration:1 delay:0.f options:(UIViewAnimationOptionTransitionNone)
                             animations:
             ^{
                 [btnCard setAlpha:0];
// Then make it disappear Or remove this line to hold the btnCard in image
             }
                             completion:^(BOOL finished)
             {
                 [btnCard removeFromSuperview];
    // Or perform any other function
             }];

    }

让我知道你是否在其他地方卡住了。

于 2013-08-01T10:40:11.510 回答