如果用户没有足够的硬币,如何阻止动作?

时间:2014-03-24 23:33:38

标签: ios objective-c

我正在修一个文字游戏,我已经制作了一个按钮,允许用户获得提示......但是提示需要10个硬币。

如果用户没有留下任何硬币并且同时警告用户购买硬币,我怎么能阻止这个动作呢?

-(IBAction)btnHint:(id)sender {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];

    CGPoint center = [hints center];
    center.x = 160;
    center.y = 230;
    [hints setCenter:center];

    [UIView commitAnimations];
    hintView.text = @"founded in 1996, and is a sub of telecome";

    coins = coins -10;
}

1 个答案:

答案 0 :(得分:1)

这样的事情:

- (IBAction)btnHint:(id)sender {
    if (/* some condition that determines if there are enough coins */) {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.5];

        CGPoint center = [hints center];
        center.x = 160;
        center.y = 230;
        [hints setCenter:center];

        [UIView commitAnimations];
        hintView.text = @"founded in 1996, and is a sub of telecome";

        coins = coins -10;
    } else {
        // show alert
    }
}
BTW - 您真的应该迁移到现代基于块的UIView动画,而不是您正在使用的旧方式。