ios - 为何按钮点击无反应?

查看:96
本文介绍了ios - 为何按钮点击无反应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

/*这段代码功能是添加按钮,视图上移,但是发现在上移的视图里,添加的按钮不响应,这是为什么呢?*/


    -(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");
    }

解决方案

界面控件超出父控件位置。
确定self.view 的frame大小,看看addview的frame 大小,再看看btn的frame位置大小,确定一层一层都在self.view的frame内~

这篇关于ios - 为何按钮点击无反应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆