简体   繁体   English

UIScrollView内的UIView上的UIButton

[英]UIButton on UIView inside UIScrollView

I have a UIScrollView (similar to that seen showing the featured items on the App Store) which has 3 views, with xibs, loaded into it. 我有一个UIScrollView(类似于在App Store上显示特色商品的视图),其中有3个带有xibs的视图加载到其中。 Everything works find except I can get the UIButtons which I have on the xibs to fire. 一切都能找到,除了我可以得到我在xibs上触发的UIButtons。 I guess I am missing something obvious just can't see it. 我想我遗漏了一些明显的东西,看不到它。 I've tried various answers on here and other places to no avail. 我在这里和其他地方尝试了各种答案,都无济于事。

Thanks in advance 提前致谢

Code from viewDidLoad on ViewController containing scroll view 来自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 - Code for one of the views loaded into the scroll view (other 2 are the same) 编辑-加载到滚动视图中的视图之一的代码(其他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

Screenshots 屏幕截图 显示带有滚动视图的视图控制器

显示加载到scrollview的视图

通过在添加到滚动视图之前设置视图的帧大小来解决此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM