2011-04-24 25 views
0

我正在使用帶有兩個按鈕的UIImageView,作爲子視圖添加到我的應用程序中。但是,如果我嘗試點擊按鈕,它們沒有響應。有沒有這個原因,或修復?添加到UIImageView中的按鈕無響應

- (void)showPopover { 
    if (isClicked == NO) { 
     if (popover == nil) { 
      popover = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Popover.png"]]; 
      [popover setFrame:CGRectMake(190, -10, 132, 75)]; 
      UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom]; 
      [btn1 setFrame:CGRectMake(30, 30, 24, 24)]; 
      [btn1 setBackgroundColor:[UIColor clearColor]]; 
      [btn1 setImage:[UIImage imageNamed:@"Bookmark.png"] forState:UIControlStateNormal]; 
      [btn1 addTarget:self action:@selector(addFav) forControlEvents:UIControlStateNormal]; 
      [popover addSubview:btn1]; 

      UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom]; 
      [btn2 setFrame:CGRectMake(80, 30, 24, 24)]; 
      [btn2 setBackgroundColor:[UIColor clearColor]]; 
      [btn2 setImage:[UIImage imageNamed:@"ButtonBarReload.png"] forState:UIControlStateNormal]; 
      [btn2 addTarget:self action:@selector(doHud) forControlEvents:UIControlStateNormal]; 
      [popover addSubview:btn2]; 
      isClicked = YES; 
     } 
     popover.alpha = 0.0; 
     isClicked = YES; 
     [self.view.superview addSubview:popover]; 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:1.0]; 
     popover.alpha = 1.0; 
     [UIView commitAnimations]; 
    } 
    else if (isClicked == YES) { 
     [popover setAlpha:1.0]; 
     isClicked = NO; 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:1.0]; 
     [popover setAlpha:0.0]; 
     [popover removeFromSuperview]; 
     [UIView commitAnimations]; 
     popover = nil; 
     [popover release]; 
    } 
} 

回答

2

默認情況下,圖像視圖設置爲禁用用戶交互。嘗試imageView.userInteractionEnabled = YES;

1

組userInteractionEnabled爲YES

對於的UIImageView ....

該屬性是從 UIView的父類繼承。此類 將此 屬性的默認值更改爲NO。