Here is my code, if I add the CABasicAnimation,
the UITouch *touch = [[event allTouches] anyObject]; will return to MainView not UIImageView,
is there other way to add the CABasicAnimation?
MainView.m
the UITouch *touch = [[event allTouches] anyObject]; will return to MainView not UIImageView,
is there other way to add the CABasicAnimation?
MainView.m
Code:
- (void)createGame:(int)numberDot
{
for(int i = 0; i <numberDot; i++) {
float xPos = 0;
float yPos = 60 * i;
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(xPos, yPos, 57.0, 57.0)];
imageView.image =[UIImage imageNamed:@"Icon8.png"];
imageView.userInteractionEnabled = YES;
[self addSubview:imageView];
[imageViewArray insertObject:imageView atIndex:i];
CABasicAnimation *theAnimation;
theAnimation = [CABasicAnimation animationWithKeyPath:@"position.x"];
theAnimation.duration = 20.0;
theAnimation.repeatCount = 2;
theAnimation.autoreverses = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:10.0];
theAnimation.toValue = [NSNumber numberWithFloat:300.0];
[[imageView layer] addAnimation:theAnimation forKey:@"animateOpacity"];
[imageView release];
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
for(int i = 0; i < [imageViewArray count]; i++)
{
id anObject = [[imageViewArray objectAtIndex:i] retain];
if([touch view] == anObject)
{
[anObject removeFromSuperview];
[imageViewArray removeObjectAtIndex:i];
}
}
}