Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

uibutton - My Custom Button is not getting click in iCarousel iOS?

In my example I am using iCarousel in which I am trying to expand image on clicking on it? What I have done,after image expands I am adding backButton on right bottom corner of view so that I can return to the original view. But that button is not getting click event. Where am I going wrong?

here is my code.

- (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];
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I also had the same problem but I have resolved with below code.

view.userInteractionEnabled = YES;

view = your carousel view item

OR

[yourButton.superview setUserInteractionEnabled:YES];

hope it helps to others.

cheers!!!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...