我正在编写一个按钮,当它被按下时发射弹丸。但是,我试图禁用此按钮,直到我希望它被使用。这是我的代码,这是行不通的:按钮不会禁用IOS目标C
#import "GameViewController.h"
@interface GameViewController()
@end
@implementation GameViewController
//What happens when shoot button is pressed
-(IBAction)Shoot:(id)sender{
Shoot.enabled = NO;
//Step 1: upload image Step 2: Load image into image view Step 3: set coordinates and size
UIImage * Bulletimage= [UIImage imageNamed:@"bullet.png"];
UIImageView * Bullet = [[UIImageView alloc] initWithImage:Bulletimage];
[Bullet setFrame:CGRectMake(130,430,35,35)];
[self.view addSubview:Bullet];
//Creating Animation
[UIView animateWithDuration:0.7 delay:0 options: UIViewAnimationOptionAllowAnimatedContent animations:^{ [Bullet setFrame:
CGRectMake (130, 20, 35, 35)];}
completion:^(BOOL finished) {Bullet.hidden = YES;}];
}
//what happens when ready button is pressed
-(IBAction)Ready:(id)sender{
//button disapears
Ready.hidden = YES;
}
-(IBAction)Ready2:(id)sender{
//button disapears
Ready2.hidden = YES;
if (Ready.hidden= YES, Ready2.hidden = YES)
{
//declaring images for animation
Countdown.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"1.png"],
nil];
[Countdown setAnimationRepeatCount:1];
Countdown.AnimationDuration = 3;
[Countdown startAnimating];
//end of loop
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
动画是否发生? – 2014-10-02 23:09:24
“不起作用”是什么意思?这句话中几乎没有任何信息。 – Fogmeister 2014-10-02 23:30:59