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

查看:20
本文介绍了我的自定义按钮在 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天全站免登陆