我放置了三个按钮,第一个按钮允许动画显示其他按钮,但用户应该只在每个动作上花费10点。
这意味着当他们按下按钮#2时,他们只会损失10个金币(-10个金币),行动#3也是如此。
-(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";
if(minusPoint) { coins = coins -10;
//Minus a point
minusPoint = NO;
}
}
- (IBAction)firstHintq:(id)sender {
hintView.text = @"founded in 1996, and is a sub of telecome";
}
- (IBAction)secondHintq:(id)sender {
[_candletwo setImage:[UIImage imageNamed:@"candle2_03.png"] forState:UIControlStateNormal];
hintView.text = @"Type in text here 2";
}
- (IBAction)thirdHintq:(id)sender {
hintView.text = @"Type in the third hint here";
[_candlethree setImage:[UIImage imageNamed:@"candle2_03.png"] forState:UIControlStateNormal];
}
我如何在硬币标签上立即显示-10分?
设置conins
为int类型的全局变量。设硬币标号为coinLabel
。将3 bool
设为全局变量,如btn1Pressed,btn2Pressed,btn3Pressed
。在viewDidLoad
中,make为btn1Pressed = btn2Pressed = btn3Pressed =false;
。然后像这样做:
-(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";
}
- (IBAction)firstHintq:(id)sender {
hintView.text = @"founded in 1996, and is a sub of telecome";
if(!btn1Pressed) {
if((coins -10) >= 0){
coins = coins -10;
btn1Pressed = true
coinLabel.text = [NSString stringWithFormat:@"%d",coins];
}
else{
//Show an alert that the user has not enough coins
}
}
}
- (IBAction)secondHintq:(id)sender {
[_candletwo setImage:[UIImage imageNamed:@"candle2_03.png"] forState:UIControlStateNormal];
hintView.text = @"Type in text here 2";
if(!btn2Pressed) {
if((coins -10) >= 0){
coins = coins -10;
btn2Pressed = true
coinLabel.text = [NSString stringWithFormat:@"%d",coins];
}
else{
//Show an alert that the user has not enough coins
}
}
}
- (IBAction)thirdHintq:(id)sender {
hintView.text = @"Type in the third hint here";
[_candlethree setImage:[UIImage imageNamed:@"candle2_03.png"] forState:UIControlStateNormal];
if(!btn3Pressed) {
if((coins -10) >= 0){
coins = coins -10;
btn3Pressed = true
coinLabel.text = [NSString stringWithFormat:@"%d",coins];
}
else{
//Show an alert that the user has not enough coins
}
}
}
希望这对你有帮助。:)