2012-11-20 56 views
7

我有一个scrollView,它有一个UIView作为子视图。这有UIView子视图UIButton。只有scrollView连接到插座,其余全部在代码中。按钮不响应触摸,触摸时不会变为蓝色。我能做些什么来使它工作?UIButton在uiscroll中不起作用查看

这是代码:

- (void)viewDidLoad 
{ 
     [super viewDidLoad]; 

     //...... 

     self.buttonHome = [UIButton buttonWithType:UIButtonTypeCustom]; 
     [self.buttonHome addTarget:self action:@selector(pressedHome:) 
            forControlEvents:UIControlEventTouchUpInside]; 
     //.... 
     self.containerView =[[UIView alloc]initWithFrame:self.scrollView.frame]; 
     self.containerView.userInteractionEnabled=YES; 

     [self.scrollView addSubview:self.containerView]; 
     [self.containerView addSubview:self.buttonHome]; 
    } 

    -(void) pressedHome:(id)sender{ 
     //.... 
    } 
+0

我模拟你提到的工作,但它对我来说工作正常 –

+0

对我而言无效。没有UIView完美的工作,但这个UIView是必要的缩放 –

回答

1

我解决这个问题

- (BOOL)touchesShouldCancelInContentView:(UIView *)view 
    { 
     return ![view isKindOfClass:[UIButton class]]; 
    } 

既然问题是放一个按钮UIButton

0

确保您的滚动视图不吞咽的亮点: 检查这个其他SO question

4

您必须设置视图的内容大小。这必须大于或等于scrollView的内容大小。

因为您的视图的默认大小是320 * 480(3.5“视网膜)和320 * 568(4”视网膜)。因此增加视图的高度为-

self.view.frame = CGRectMake(0,0,320,700);

然后添加这个作为你的scrollView的子视图。

将帮助您解决问题。

-1

使containerView视图高度与scrollView Height相同。