2011-10-18 4 views
0

だから私はこのようなUIImageViewNSMutableArrayを作成:center.xとcenter.yにuiimageviewsの配列がありますか?

NSMutableArray* imageViewArray = [[NSMutableArray alloc] init]; 
for(int i = 0; i < 15; i++){ 
    UIImageView* imageView = [self animationInit:imageArray xPos:0 yPos:480 wFrame:32 
                 hFrame:32 duration:0.5 repeat:0]; 
    [imageViewArray addObject:imageView]; 
    [imageView release]; 
    imageView = nil; 
    [self.view addSubview:[imageViewArray objectAtIndex:i]]; 
} 

方法「animationInitは」私はUIImageViewを初期化するために作成する方法です。私はこのように使用して、配列内の各UIImageViewの中心を設定することができる午前

-(UIImageView*)animationInit:(NSArray*)imageArray xPos:(float)x yPos:(float)y wFrame: 
        (float)w hFrame:(float)h duration:(float)duration repeat:(float)count { 
    UIImageView* imageAnimation = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)]; 
    imageAnimation.animationImages = imageArray; 
    imageAnimation.animationDuration = duration; 
    imageAnimation.animationRepeatCount = count; 

    return imageAnimation; 
} 

[imageViewArray objectAtIndex:Index] setCenter:CGPointMake(x, y)]; 

今、私はxyを変更することはできませんしたいと思い、その実装はこれです私は通常のUIImageViewと思っています。例:

ここでの問題は、UIImageViewsの配列内の "UIImageView.center.x/y"にアクセスする方法がわかりません。私が "setCenter:"とできるように "center.x/y"にアクセスする方法はありますか?の中のxyを保持するためにCGPointsの束を作る方が良いでしょうか?

私が[imageViewArray objectAtInded:Index].center.xを試すと、次のエラーが発生します。

Request for member 'center' in something no a structure or union

解決策または回避策はありますか?

+0

あなたはできる、アレイ内の画像ビューをループし、その中央プロパティを変更します。あなたはそれで何が問題になっていますか? – EmptyStack

+0

申し訳ありません私は私がしたいことを説明することでそれほど良くはないと思います。[[imageViewArray objectAtIndex:Index] setCenter:CGPointMake([imageViewArray objectAtIndex:Index] .x + 5、[imageViewArray objectAtIndex:Index] y + 5])];しかし、明らかにこれは私がそれを書いた方法では不可能です。これは今より意味をなさないでしょうか? – RickyTheCoder

+0

あなたはそれをそうすることができますか?なぜそれは不可能だと言いますか? – EmptyStack

答えて

0

UIImageViewsの配列のxyの値にアクセスするには、次のものを使用する必要があります。

[imageViewArray objectAtIndex:Index] center].x 

これで、以下を使用できました。このよう

UIImageView.center = CGPointMake(UIImageView.center.x + 5, UIImageView.center.y + 5); 

[[imageViewArray objectAtIndex:Index] setCenter:CGPointMake([imageViewArray objectAtIndex:Index] center].x + 5, [imageViewArray objectAtIndex:Index] center].y + 5)]; 

混乱と私が引き起こしている可能性の混乱のために再び申し訳ありません。私は自分自身のものをこのものと混同しました。

(私は解決策を発見し、それが最高の私は他の誰が同じ問題に遭遇し念のためにそれを共有すると思った。)

関連する問題