我有一个动画熊的代码,但我需要检查它的动画和常规UIImageView之间的碰撞。有什么建议?我查看了其他答案但我的代码却不一样。这是我到目前为止所拥有的。或者我应该使用SpriteKit。我宁愿不要。
- (void)viewDidLoad {
NSArray *imageNames = @[@"bear1.gif", @"bear2.gif", @"bear3.gif", @"bear4.gif",
@"bear5.gif", @"bear6.gif"];
NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
[images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}
// Normal Animation
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(768, 800, 169, 217)];
animationImageView.animationImages = images;
animationImageView.animationDuration = 0.5;
[self.view addSubview:animationImageView];
[animationImageView startAnimating];
[UIView animateWithDuration:7 delay:1 options:UIViewAnimationOptionRepeat animations:^{
[UIView setAnimationRepeatCount:INFINITY];
animationImageView.frame = CGRectMake(-10, 800, 169, 217);
} completion:^(BOOL finished) {
animationImageView.hidden = YES;
}];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
答案 0 :(得分:0)
在动画块中,您可以查看动画视图的帧何时越过或即将穿过UIImageView的帧。满足此条件时,您将停止动画