2012-09-24 28 views
0

我想創建一個撥號盤,並且當點擊dial.i中的圖像時想獲取圖像的標籤,但嘗試了很多,但是我沒有「噸得到it.see下面如何檢測圖像子視圖的標籤,當我在旋轉的uiview中觸摸圖像時

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

{

//我想cloveImage.tag當我點擊了imageview的

}

所以我的問題是如何檢測圖像的標籤在旋轉的車輪,當我摸到
特定圖像?

回答

0

我建議你添加,而不是在UIImageView的按鈕,然後到uibuttons.As添加背景圖片就獲得標籤而言,你必須獲得點擊buuton相應標籤在其目標方法

+0

我試過太多,但方法willnot得到 – Vivek2015

+0

讓我看看你的方法.. – AppleDelegate

0
for (UIImageView *img in self.view.subviews) 
    { 
     if ([img isKindOfClass:[UIImageView class]]) 
     { 
      if (img.tag==index) 
      { 
       Your code.... 
      } 
     } 

    } 

你使用上面的代碼通過使用for循環得到Perticular圖像的THA標籤..

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); 
}