我有一个UIScrollView(类似于在App Store上显示的特色项目),它有3个视图,其中加载了xib。一切正常,除了我可以得到我在xibs上的UIButton来解雇。我想我错过了一些明显无法看到的东西。我在这里和其他地方尝试过各种答案都无济于事。
提前致谢
来自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);
EDIT - 加载到滚动视图中的其中一个视图的代码(其他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
截图
答案 0 :(得分:0)
通过在将视图添加到scrollview
之前设置视图的帧大小来解决此问题