我正在編寫一個按鈕,當它被按下時發射彈丸。但是,我試圖禁用此按鈕,直到我希望它被使用。這是我的代碼,這是行不通的:按鈕不會禁用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