2014-03-03 3 views
3

내 예제에서 나는 클릭하여 이미지를 확장하려고하는데 iCarousel을 사용하고 있습니까? 이미지를 확장 한 후 을 오른쪽 하단 모서리에 view에 추가하여 원본보기로 되돌릴 수 있습니다. 하지만 그 버튼은 클릭 이벤트를 얻지 못합니다. 내가 어디로 잘못 가고 있니?내 맞춤 검색 버튼이 iCarousel iOS에서 클릭을 얻지 못합니까?

여기 내 코드입니다.

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{ 
UIButton *button = (UIButton *)view; 
UIView *buttonBackView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 475, 300)]; 
[buttonBackView setBackgroundColor:[UIColor blackColor]]; 
button = [UIButton buttonWithType:UIButtonTypeCustom]; 
button.frame = CGRectMake(0.0f, 0.0f, 475,300); 

UIImage *image=[_rareCSNYArrayImageItems objectAtIndex:index]; 
[button setBackgroundImage:image forState:UIControlStateNormal]; 

[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; 

[buttonBackView addSubview:button]; 
return buttonBackView; 

} 


    - (void)buttonTapped:(UIButton *)sender 
{ 
UIButton *button=(UIButton*)sender; 
[button setFrame:CGRectMake(0,0,675,400)]; 
[button.superview setFrame:CGRectMake(-100, -70, 675, 500)]; 
UIButton *buttonReduce=[[UIButton alloc] initWithFrame:CGRectMake(580, 405, 85, 85)]; 
[buttonReduce setBackgroundColor:[UIColor clearColor]]; 
[buttonReduce setBackgroundImage:[UIImage imageNamed:@"reducebuutton.png" ] forState:UIControlStateNormal]; 
[buttonReduce addTarget:self action:@selector(buttonReduceTapped:) forControlEvents:UIControlEventTouchUpInside]; 
[button.superview addSubview:buttonReduce]; 
[self.view bringSubviewToFront:buttonReduce]; 
} 

- (void)buttonReduceTapped:(UIButton *)sender{ 

UIButton *button=(UIButton*)sender; 
NSLog(@"ButtonClicked"); 
[button.superview setFrame:CGRectMake(0, 0, 475, 300)]; 
[button removeFromSuperview]; 
} 
+1

버튼의 수퍼 뷰에서 userInteraction이 활성화되어 있는지 확인합니다. – croyneaus4u

+0

@ croyneaus4u 여전히 작동하지 않습니다. –

답변

2

단추가 슈퍼 뷰의 경계를 벗어나는 것일 수 있습니다. iOS 뷰는 슈퍼 뷰 경계 외부로 그려 질 수 있지만 해당 경계 외부에서 터치 이벤트를 수신하지 않습니다.

버튼이 회전식 안에있는 경우 iCarousel보기에서 clipsToBounds를 활성화하여 이론을 테스트 해보십시오. 캐 러셀 항목보기에있는 경우 iCarousel 항목보기에서 클립을 사용하도록 설정하십시오.

캐 러셀 안에있는 경우 외부로 이동하거나 캐 러셀 프레임을 더 크게 만듭니다. 그러나 항목보기 안에 있으면 iCarousel이 내부적으로 작동하는 방식 때문에 개별 회전식보기를 더 크게 만들 수 없습니다.

그런 경우이를 해결하기 위해 확장 뷰를 그 내부가 아닌 회전식 캐너 앞에 그리는 것이 좋습니다. 애니메이션을보다 쉽게 ​​만들려면 현재 수행중인 캐 러셀 내부에서 이미지 확대/축소를 애니메이션으로 만들 수 있지만 애니메이션 끝 부분에서보기를 슈퍼 뷰 계층의 맨 앞으로 이동하면 사용자가 전환.

5

나는 또한 동일한 문제가 있었지만 아래 코드로 해결했습니다.

view.userInteractionEnabled = YES; 

보기 = 당신의 회전 목마보기 항목

또는

[yourButton.superview setUserInteractionEnabled:YES]; 

은 다른 사람에게 도움이되기를 바랍니다.

건배 !!!!

+0

감사합니다. 작동합니다. – vijay

+0

감사합니다. 내 문제를 해결했습니다. – ASV