0

ダイアルを作成したいのですが、ダイアル内の画像をクリックしたときに画像のタグを取得したいです。いろいろ試しましたが、取得できませんでした。以下のコードを参照してください。

- (void) drawWheel {

container = [[UIView alloc] initWithFrame:self.frame];

CGFloat angleSize = 2*M_PI/numberOfSections;

for (int i = 0; i < numberOfSections; i++) {

    UIImageView *im = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"segment.png"]];

    im.layer.anchorPoint = CGPointMake(1.0f, 0.5f);
    im.layer.position = CGPointMake(container.bounds.size.width/2.0-container.frame.origin.x, 
                                    container.bounds.size.height/2.0-container.frame.origin.y); 
    im.transform = CGAffineTransformMakeRotation(angleSize*i);
    im.alpha = minAlphavalue;
    im.tag = i;

    if (i == 0) {
        im.alpha = maxAlphavalue;
    }

    cloveImage = [[UIImageView alloc] initWithFrame:CGRectMake(12, 15, 40, 40)];
    cloveImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"icon%i.png", i]];
    cloveImage.tag=i;
   [im addSubview:cloveImage];

}

    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

//imageview をクリックしたときに cloveImage.tag を取得したい

}

だから私の質問は、
特定の画像に触れたときに回転ホイールで画像のタグを検出するにはどうすればよいですか?

4

3 に答える 3

0

これを試して:

... ...
cloveImage = [[UIImageView alloc] initWithFrame:CGRectMake(12, 15, 40, 40)];
cloveImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"icon%i.png", i]];
cloveImage.tag=i;
//   **********add begin**********
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showCloveImageTagOnImageView:)];
[cloveImage addGestureRecognizer:tapGR];
//   **********add end**********
[im addSubview:cloveImage];
... ...



//  copy the selector below and log the cloveImageTag
- (void)showCloveImageTagOnImageView: (UIImageView *)tappedImageView
{
    NSLog(@"tappedImageView.tag: %d", tappedImageView.tag);
}
于 2012-09-24T10:01:47.287 に答える
0
for (UIImageView *img in self.view.subviews)
    {
        if ([img isKindOfClass:[UIImageView class]])
        {
            if (img.tag==index)
            {
                Your code....
            }
        }

    }

for ループを使用して Perticular 画像のタグを取得するには、上記のコードを使用します。

于 2012-09-24T09:43:38.860 に答える
0

代わりにUIImageViewにボタンを追加してから、背景画像をuibuttonsに追加することをお勧めします。タグの取得に関する限り、ターゲットメソッドでクリックされたボタンの対応するタグを取得する必要があります

于 2012-09-24T09:25:35.390 に答える