我正在修一个文字游戏,我已经制作了一个按钮,允许用户获得提示......但是提示需要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;
}
答案 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
动画,而不是您正在使用的旧方式。