Hi all
I have this class called ballImage which is an UIImageView. I instantiate it from my main viewcontroller (myFirstGameViewController) like this:
Code:
ballImage *ball = [[ballImage alloc] initWithImage:[UIImage imageNamed:@"Ball.png"]];
ball.center = CGPointMake(100,100);
[ball setUserInteractionEnabled:YES];
[self.view addSubview:ball];
Below is my class where i'd like to animate the ball when it is touched. I can't use self.view since i am now in a subview so how do i access the "main view"? (see the "Error"-line)
Code:
#import "ballImage.h"
#import "myFirstGameViewController.h"
@implementation ballImage
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
NSArray * imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"Ball.png"],
[UIImage imageNamed:@"Ball2.png"],
[UIImage imageNamed:@"Ball3.png"],
nil];
UIImageView * jump = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 116, 116)];
jump.animationImages = imageArray;
jump.animationDuration = 1.1;
jump.contentMode = UIViewContentModeBottomLeft;
[self.myFirstGameViewController.view addSubview:jump]; // <--Error!
[jump startAnimating];
}
BTW i don't want to move or shrink the ball i want it to puncture so i have made a few images to do this.
Thanks in advance.