我的实现文件中有一些错误导致我无法编译,但我无法弄明白。在此先感谢您的帮助。
已注释掉错误消息:
实施档案:
#import "TNRViewController.h"
@implementation TNRViewController //'@end' is missing in implementation context
@synthesize myIcon, myBackground, bgImages, shrinkButton;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
hasMoved = NO;
hasShrunk = NO;
currentBackground = 0;
bgImages = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"WallPaper_01.png"],
[UIImage imageNamed:@"WallPaper_02.png"],
[UIImage imageNamed:@"WallPaper_03.png"],
[UIImage imageNamed:@"WallPaper_04.png"],
[UIImage imageNamed:@"WallPaper_05.png"],
nil];
size = CGAffineTransformMakeScale(.25, .25);
translate = CGAffineTransformMakeTranslation(0,-100);
myBackground.image = [bgImages objectAtIndex:currentBackground];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)dealloc {
[myIcon release];
[myBackground release];
[shrinkButton release];
[super dealloc];
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if (CGRectContainsPoint([myIcon frame], [touch locationInView:nil])); // if statement has empty body
{
if (hasMoved == YES && hasShrunk == YES) {
myIcon.transform = CGAffineTransformTranslate(size, 0, 0);
hasMoved = NO;
}
if (hasMoved == YES && hasShrunk == NO) {
myIcon.transform = CGAffineTransformMakeTranslation(0, 0);
hasMoved = NO;
}
myIcon.center = [touch locationInView:nil];
}
}
- (IBAction)shrink:(id)sender {
if (hasShrunk) {
[shrinkButton setTitle:@"Shrink" forState:UIControlStateNormal];
} else {
[shrinkButton setTitle:@"Grow" forState:UIControlStateNormal];
}
if (hasShrunk == NO && hasMoved == NO) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
myIcon.transform = size;
[UIView commitAnimations];
hasShrunk = YES;
}
else if (hasShrunk == NO && hasMoved == YES) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
myIcon.transform = CGAffineTransformScale(translate, .25, .25);
[UIView commitAnimations];
hasShrunk = YES;
}
else if (hasShrunk == YES && hasMoved == YES) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
myIcon.transform = CGAffineTransformScale(translate, 1, 1);
[UIView commitAnimations];
hasShrunk = NO;
}
else {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
myIcon.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
hasShrunk = NO;
}
}
- (IBAction)move:(id)sender {
if (hasMoved == NO && hasShrunk == NO) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
myIcon.transform = translate;
[UIView commitAnimations];
hasMoved = YES;
}
else if (hasMoved == NO && hasShrunk == YES){
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
myIcon.transform = CGAffineTransformTranslate(size, 0, -100);
[UIView commitAnimations];
hasMoved = YES;
}
else if (hasMoved == YES && hasShrunk == YES){
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
myIcon.transform = CGAffineTransformTranslate(size, 0, 0);
[UIView commitAnimations];
hasMoved = YES;
}
else
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
myIcon.transform = CGAffineTransformMakeTranslation(0, 0);
[UIView commitAnimations];
hasMoved = YES;
}
}
- (IBAction)change:(id)sender {
currentBackground++;
if(currentBackground >= [bgImages count])
currentBackground = 0;
[UIView beginAnimations:@"changeview" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (currentBackground == 1) {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
if (currentBackground == 2) {
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
if (currentBackground == 3) {
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
if (currentBackground == 4) {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[UIView commitAnimations];
[myBackground.image = [bgImages objectAtIndex:currentBackground]; //Expected identifier
}
标题文件:
#import <UIKit/UIKit.h>
@interface TNRViewController : UIViewController
{
IBOutlet UIImageView *myIcon;
IBOutlet UIImageView *myBackground;
IBOutlet UIButton *shrinkButton;
NSArray *bgImages;
int currentBackground;
bool hasMoved;
bool hasShrunk;
CGAffineTransform translate;
CGAffineTransform size;
}
@property (retain, nonatomic)IBOutlet UIImageView *myIcon;
@property (retain, nonatomic)IBOutlet UIImageView *myBackground;
@property (retain, nonatomic)NSArray *bgImages;
@property (retain, nonatomic)IBOutlet UIButton *shrinkButton;
- (IBAction)shrink:(id)sender;
- (IBAction)move:(id)sender;
- (IBAction)change:(id)sender;
@end
答案 0 :(得分:1)
以下是您对源文件发表评论的错误。
首先:
@implementation TNRViewController //'@end' is missing in implementation context
这意味着您在end
文件末尾缺少@ .m
。
第二
[myBackground.image = [bgImages objectAtIndex:currentBackground]; //Expected identifier
应该是:
myBackground.image = [bgImages objectAtIndex:currentBackground];
第三
if (CGRectContainsPoint([myIcon frame], [touch locationInView:nil])); // if statement has empty body
应该是
if (CGRectContainsPoint([myIcon frame], [touch locationInView:nil])) // Remove the semi column