我放置了三个按钮,第一个按钮允许动画显示其他按钮,但用户每次操作只能花费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点?
答案 0 :(得分:0)
使conins
类型为int的全局。让硬币标签为coinLabel
。制作3个bool
全局变量,例如btn1Pressed,btn2Pressed,btn3Pressed
。在viewDidLoad
制作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
}
}
}
希望这会有所帮助.. :)