[英]UIImageView and UIVIew animations
I need to create moving image from bot to top, with different speed of moving and size. 我需要创建从机器人到顶部的移动图像,并具有不同的移动速度和大小。 I wrote this:
我这样写:
NSInteger random=arc4random()%10;
random += 10;
for (NSInteger curImage = 0 ; curImage < random; curImage++)
{
UIImageView *tmpImage = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ball" ofType:@"png"]]];
[self addSubview:tmpImage];
[self sendSubviewToBack:tmpImage];
tmpImage.tag = imageTag;
NSInteger sizeImage = arc4random()%4;
sizeImage += 1;
tmpImage.frame = CGRectMake(0.0,0.0, sizeImage * 10.0, sizeImage * 10.0);
tmpImage.contentMode = UIViewContentModeScaleToFill;
NSInteger xStartPosition = arc4random()%1024, yStartPosition = arc4random()%748;
tmpImage.center = CGPointMake( xStartPosition , yStartPosition + self.frame.size.height);
[UIView animateWithDuration:6.0f
animations:^{
[tmpImage setFrame:CGRectMake(tmpImage.frame.origin.x, - tmpImage.image.size.height - self.frame.size.height, tmpImage.frame.size.width, tmpImage.frame.size.height)];
}
completion:^(BOOL finished){
}
];
}
For deleting I use: 对于删除,我使用:
for (UIImageView *img in [self subviews]) {
if (img.tag==imageTag) {
if (img.frame.origin.y > 0 ) {
[img removeFromSuperview];
}
}
}
But my app crash Exited: Killed: 9
. 但是我的应用程序崩溃已
Exited: Killed: 9
。
May be I can make it in another way? 可能我可以用其他方式做到吗? Any ideas???
有任何想法吗???
Thanks for help!!! 感谢帮助!!!
<Warning>: Application 'UIKitApplication:Name.Name' exited abnormally with signal 9: Killed: 9
error: ::read ( 5, 0x1df9fc, 18446744069414585344 ) => -1 err = Bad file descriptor (0x00000009)
libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Best if you enable breakpoint and check where it's crashing. 最好是启用断点并检查崩溃的位置。
Add exception break point to your xcode: 将异常断点添加到您的xcode:
https://developer.apple.com/library/ios/recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint.html https://developer.apple.com/library/ios/recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint.html
But my guess is you are modifying an array while iterating it. 但是我的猜测是您在迭代时正在修改数组。 While going through [self subviews] you indirectly modify it when you call [img removeFromSuperView].
通过[自我子视图]时,您可以在调用[img removeFromSuperView]时间接对其进行修改。
Try this: 尝试这个:
NSMutableArray* toRemove = [NSMutableArray arrray];
for (UIImageView *img in [self subviews]) {
if (img.tag==imageTag) {
if (img.frame.origin.y > 0 ) {
[toRemove addObject:img];
}
}
}
for (UIImageView *img in toRemove) {
[img removeFromSuperview];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.