2011-04-24 6 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

세트

이 속성은 UIView의 부모로부터 상속된다 ....

UIImageView에 들어

YES로 userInteractionEnabled. 이 클래스 은이 속성의 기본값을 NO로 변경합니다.

관련 문제