我的“自定义按钮"没有在iCarousel iOS中获得点击? [英] My Custom Button is not getting click in iCarousel iOS?

查看:106
本文介绍了我的“自定义按钮"没有在iCarousel iOS中获得点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的示例中,我正在使用 iCarousel ,在其中尝试点击它来扩展图像吗? 我所做的,在图像扩展之后,我在view的右下角添加了backButton,以便可以返回到原始视图.但是该按钮没有发生点击事件.我要去哪里错了?

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?

这是我的代码.

- (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];
}

推荐答案

该按钮可能不在其超级视图的范围之内. iOS视图可以在其超级视图范围之外绘制,但不会在这些范围之外接收触摸事件.

The button is probably outside the bounds of it's superview. iOS views can be drawn outside of their superview bounds, but won't receive touch events outside those bounds.

如果按钮在轮播中,请尝试在iCarousel视图上启用clipsToBounds来测试理论.如果它在轮播项目视图中,请尝试在iCarousel项目视图中启用clipsToBounds.

If the button is inside the carousel, try enabling clipsToBounds on the iCarousel view to test the theory. If it's inside a carousel item view, try enabling clipsToBounds on your iCarousel item views.

如果它在转盘内,则将其移到外面,或者只是使转盘框架变大.但是,如果它在项目视图中,则由于iCarousel在内部的工作方式,您无法轻松地动画化使各个轮播视图更大.

If it's inside the carousel, either move it outside, or just make the carousel frame bigger. But if it's inside an item view, you can't easily animate making individual carousel views bigger because of the way iCarousel works internally.

在这种情况下,要解决此问题,建议您在转盘前面而不是在转盘内部绘制展开的视图.为了使动画更容易,您可以像目前一样在旋转木马中对图像缩放进行动画处理,但随后在动画结束时将视图移动到超级视图层次结构的前面,因此用户看不到切换.

In that case, to fix it, I suggest drawing your expanded view in front of the carousel rather than inside it. To make it easier to animate, you could animate the image zoom while inside the carousel as you are doing currently, but then move the view to the front of the superview hierarchy at the end of the animation, so the user doesn't see the switchover.

这篇关于我的“自定义按钮"没有在iCarousel iOS中获得点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆