ios - 为何按钮点击无反应?
PHPz
PHPz 2017-04-17 17:59:40
0
6
306
/*这段代码功能是添加按钮,视图上移,但是发现在上移的视图里,添加的按钮不响应,这是为什么呢?*/


    -(void)showView
    {
        UIView *addView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREENSIZE.height,SCREENSIZE.width, 80)];
        [addView setBackgroundColor:[UIColor whiteColor]];
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 80, 40)];
        [btn setTitle:@"相册" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(openPhoto1) forControlEvents:UIControlEventTouchUpInside];
        [addView addSubview:btn];
        [self.view addSubview:addView];
        
        //计算控制器的view需要平移的距离
        CGFloat moveY=0;
        if (_bShowAddView==false)
            moveY  = -80;
        else
            moveY=0;
        _bShowAddView=!_bShowAddView;
        //
        //    // 4,执行动画
        [UIView animateWithDuration:0.5 animations:^{
            self.view.transform = CGAffineTransformMakeTranslation(0, moveY);
        }];
    }
    -(void)openPhoto1
    {
        NSLog(@"test");
    }
PHPz
PHPz

学习是最好的投资!

reply all(6)
Peter_Zhu

The interface control exceeds the position of the parent control.
Determine the frame size of self.view, look at the frame size of addview, and then look at the frame position size of btn, and make sure that each layer is within the frame of self.view~

左手右手慢动作

Yes, addview is out of scope and the object used for animation is wrong. Thank you.

小葫芦

I don’t understand what you want to write, but the Y and height of frme in UIView *addView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREENSIZE.height,SCREENSIZE.width, 80)]; are set wrong. Please change them. You can order it in one click

PHPzhong

UIView是需要添加交互效果的,默认是不能接到点击效果, set the attribute that accepts click effects to YES and you’re done

Peter_Zhu

Either it is beyond the scope of the parent control or the interaction of the parent control is not allowed

迷茫

If you have to interact, there is a way

  1. Customize an irregular parent view (I guess you don’t know how to ask this question)

  2. Redefine the position relative to the parent view in the touch event of the view

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template