UIscrollview下方的按钮在滚动期间被禁用或不起作用

时间:2016-03-18 07:49:49

标签: ios objective-c uiscrollview uibutton

我将按钮放在滚动视图下方并启用垂直滚动。滚动后,按钮可见,如果我点击按钮不起作用。

1.此图片显示了故事板"其中包含"表格视图"在里面"滚动视图"和"按钮"放在"滚动视图" "按钮"显示在"蓝色"。

故事板中的滚动视图规范(0,83,568,237)

故事板中的表视图规范(2,4,564,229)

enter image description here

2.此图像显示"视图"没有滚动。

enter image description here

3.此图像代表"垂直滚动"朝着"向上"方向。

我的一段代码用于"垂直滚动"

[_scroller setScrollEnabled:YES];
[_scroller setContentSize:CGSizeMake(_scroller.bounds.size.width, _scroller.bounds.size.height*3)];

我的代码用于显示" scrollview" "的tableview""按钮"同样在iPad和iPhone中:

[_tblview setFrame:CGRectMake(0,80,self.view.frame.size.height,self.view.frame.size.width)];
[_scroller setFrame:CGRectMake(0,80,self.view.frame.size.height,self.view.frame.size.width)];
[_btnSave setFrame:CGRectMake(0,self.view.frame.size.width-50,50,25)];
[_btnSubmit setFrame:CGRectMake(55,self.view.frame.size.width-50,50,25)];
[_btnCancel setFrame:CGRectMake(110,self.view.frame.size.width-50,50,25)];

enter image description here

4.此图像代表"垂直滚动"向下方向。它显示三个"按钮"保存,提交,取消。向下滚动,如果我点击这些按钮中的任何一个。没有任何动作发生。这就是问题。

enter image description here

可能是什么问题。我必须改变"按钮" CGRectmake或缩小滚动视图和表视图的大小或修改UI设计,将按钮放在滚动视图的顶部。请给我一些解决方案。提前谢谢。

2 个答案:

答案 0 :(得分:0)

请检查userInteractionEnabled

outerLayer.userInteractionEnabled=YES;

答案 1 :(得分:0)

[scrolViewFrames removeFromSuperview];
scrolViewFrames=nil;
scrolViewFrames= [[UIScrollView alloc]init];
scrolViewFrames.frame= CGRectMake(0, SCREEN_HEIGHT-60, SCREEN_WIDTH, 60);
scrolViewFrames.backgroundColor= BLACK_COLOR;
[self.view addSubview:scrolViewFrames];


NSArray *cropFrames= @[@"original",@"3.2",@"16.9",@"square",@"2.1",@"3.1",@"3.4",@"7.5",@"16.10"];
NSArray *cropFramesSelected= @[@"original_sel",@"3.2_sel",@"16.9_sel",@"square_sel",@"2.1_sel",@"3.1_sel",@"3.4_sel",@"7.5_sel",@"16.10_sel"];

float _x=15;
float _y=0;
float _width=50;
float _height=60;

for (int i=0; i<cropFrames.count; i++)
{

    UIButton *threeTwoRatioButton= [UIButton buttonWithType:UIButtonTypeCustom];
    threeTwoRatioButton.frame= CGRectMake(_x, _y, _width, _height);
    threeTwoRatioButton.backgroundColor= BLACK_COLOR;
    [threeTwoRatioButton addTarget:self action:@selector(changeRatioButton:) forControlEvents:UIControlEventTouchUpInside];
    [threeTwoRatioButton setImage:[UIImage imageNamed:[cropFrames objectAtIndex:i] ]forState:UIControlStateNormal];
    [threeTwoRatioButton setImage:[UIImage imageNamed:[cropFramesSelected objectAtIndex:i] ]forState:UIControlStateSelected];
    threeTwoRatioButton.tag=400+i;
    [scrolViewFrames addSubview:threeTwoRatioButton];

    if(i==0){

        threeTwoRatioButton.selected=YES;
    }

    _x=_x+ _width +15;

}

    scrolViewFrames.contentSize= CGSizeMake(_x, _height);

this is my working code