我试图在互联网上找到答案(这个网站也是如此),但我找不到正确的答案。
我试图给按钮一个动画,所以我使用了QuartzCore Framework。但是每当我想玩它时,它就会给我带来烦人的按摩:在界面中找不到属性'newGameButton'的声明。我不知道我做错了什么或我现在要做什么。
这是我的.h和.m文件:
.h文件:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface MainMenuViewController : UIViewController {
IBOutlet UIButton* newGameButton;
IBOutlet UIButton* statsButton;
IBOutlet UIButton* settingsButton;
CAKeyframeAnimation* popAnimation;
}
-(IBAction) newGame:(id)sender;
-(IBAction) showStats:(id)sender;
-(IBAction) showSettings:(id)sender;
@end
.m文件:
#import "MainMenuViewController.h"
#import "TrafficAppDelegate.h"
#import "TrafficViewController.h"
@implementation MainMenuViewController
-(IBAction) newGame:(id)sender{
TrafficViewController* traffic = [[TrafficViewController alloc] initWithNibName:@"TrafficViewController" bundle:nil];
[self.navigationController pushViewController:traffic animated:NO];
}
-(IBAction) showStats:(id)sender{
}
-(IBAction) showSettings:(id)sender{
}
@synthesize newGameButton, statsButton, settingsButton; (This is the error causer!)
-(void)viewDidLoad{
[super viewDidLoad];
popAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
popAnimation.keyTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.7], [NSNumber numberWithFloat:1.0], nil];
popAnimation.values = [NSArray arrayWithObjects: [NSNumber numberWithFloat:0.01], [NSNumber numberWithFloat:1.1], [NSNumber numberWithFloat:1.0], nil];
[popAnimation retain];
}
-(void)popView:(UIView*)view{
[view setHidden:NO];
[[view layer] addAnimation:popAnimation forKey:@"transform.scale"];
}
-(void)viewWillAppear:(BOOL)animated{
[popAnimation setDuration:0.3];
[newGameButton setHidden:YES];
[statsButton setHidden:YES];
[settingsButton setHidden:YES];
[self performSelector:@selector(popView:) withObject:newGameButton afterDelay:0.25];
[self performSelector:@selector(popView:) withObject:statsButton afterDelay:0.3];
[self performSelector:@selector(popView:) withObject:settingsButton afterDelay:0.35];
}
@end
我完全无能为力,所以请帮忙!
答案 0 :(得分:1)
错误是自描述的 - 您需要声明在类接口中合成的属性,例如:
@interface MainMenuViewController : UIViewController {
...
}
...
@property (nonatomic, retain) IBOutlet UIButton* settingsButton;
@end
我建议(重新)阅读Objective-c reference docs
中的属性答案 1 :(得分:1)
您正在尝试访问一个根本不存在的属性。
查看您的@interface
,您看到任何@property
声明吗?
这将有效:
@interface MainMenuViewController : UIViewController {
IBOutlet UIButton* newGameButton;
IBOutlet UIButton* statsButton;
IBOutlet UIButton* settingsButton;
CAKeyframeAnimation* popAnimation;
}
@property (nonatomic, retain) IBOutlet UIButton *newGameButton, *statsButton, *settingsButton;