1

移動速度とサイズが異なる、ボットからトップへの動画を作成する必要があります。私はこれを書きました:

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 (UIImageView *img in [self subviews]) {
        if (img.tag==imageTag) {
            if (img.frame.origin.y > 0 ) {
                [img removeFromSuperview];
            }
        }
    }

しかし、私のアプリはクラッシュしExited: Killed: 9ます。

別の方法で作ることはできますか?何か案は???

手伝ってくれてありがとう!!!

クラッシュ リストの編集:

<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
4

1 に答える 1

1

ブレークポイントを有効にして、クラッシュしている場所を確認するのが最適です。

Xcode に例外ブレーク ポイントを追加します。

https://developer.apple.com/library/ios/recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint.html

しかし、反復中に配列を変更していると思います。[self subviews] を通過中に、[img removeFromSuperView] を呼び出すときに間接的に変更します。

これを試して:

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];
}
于 2013-09-10T11:21:41.413 に答える