Sah*_*ngh 3 uibutton ios icarousel
在我的例子中,我正在使用iCarousel,我试图在点击它时扩展图像?我做了什么,在图像扩展后我添加backButton到右下角,view以便我可以返回到原始视图.但是那个按钮没有获得点击事件.我哪里错了?
这是我的代码.
- (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];
}
Run Code Online (Sandbox Code Playgroud)
我也有同样的问题,但我已经解决了下面的代码.
view.userInteractionEnabled = YES;
Run Code Online (Sandbox Code Playgroud)
view =您的轮播视图项目
要么
[yourButton.superview setUserInteractionEnabled:YES];
Run Code Online (Sandbox Code Playgroud)
希望它对别人有所帮助.
干杯!!!!