![](/img/trans.png)
[英]UIButton inside UIView inside UIScrollView not firing tap action
[英]UIButton on UIView inside UIScrollView
我有一个UIScrollView(类似于在App Store上显示特色商品的视图),其中有3个带有xibs的视图加载到其中。 一切都能找到,除了我可以得到我在xibs上触发的UIButtons。 我想我遗漏了一些明显的东西,看不到它。 我在这里和其他地方尝试了各种答案,都无济于事。
提前致谢
来自ViewController上的viewDidLoad的代码,其中包含滚动视图
LSCWInfoView *view1 = [[[NSBundle mainBundle]
loadNibNamed:@"LSCW-InfoView"
owner:self options:nil]
firstObject];
CGRect frame;
frame.origin.x = 0;
frame.origin.y = 0;
frame.size = self.activityPageControl.frame.size;
[view1 setFrame:frame];
[self.activityScrollView addSubview:view1];
ScrambledInfoView *view2 = [[[NSBundle mainBundle]
loadNibNamed:@"Scrambled-InfoView"
owner:self options:nil]
firstObject];
CGRect frame2;
frame2.origin.x = 320;
frame2.origin.y = 0;
frame2.size = self.activityPageControl.frame.size;
[view2 setFrame:frame2];
[self.activityScrollView addSubview:view2];
TestInfoView *view3 = [[[NSBundle mainBundle]
loadNibNamed:@"Test-InfoView"
owner:self options:nil]
firstObject];
CGRect frame3;
frame3.origin.x = 640;
frame3.origin.y = 0;
frame3.size = self.activityPageControl.frame.size;
[view3 setFrame:frame3];
[self.activityScrollView addSubview:view3];
_activityScrollView.contentSize = CGSizeMake(_activityScrollView.frame.size.width * 3, _activityScrollView.frame.size.height);
编辑-加载到滚动视图中的视图之一的代码(其他2个相同)
#import "LSCWInfoView.h"
@implementation LSCWInfoView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
- (IBAction)lscwPlayButtonPressed:(id)sender
{
NSLog(@"YEP");
}
@end
屏幕截图
通过在添加到滚动视图之前设置视图的帧大小来解决此问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.