/*这段代码功能是添加按钮,视图上移,但是发现在上移的视图里,添加的按钮不响应,这是为什么呢?*/ -(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"); }
如果你非要交互的话也有方法
自定义一个不规则的父视图(问这问题估计你不会)
在view的触碰事件中 重新定义相对父视图的位置
要么是超出父控件范围 要么是父控件的交互不允许
UIView是需要添加交互效果的,默认是不能接到点击效果
,把接受点击效果的属性设置成YES就搞定
看不懂你想写什么,不过 UIView *addView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREENSIZE.height,SCREENSIZE.width, 80)];的frme的Y和高,设置错了吧,调换一下就可以点了
是的,addview超出了范围,使用动画的对象不对。多谢。
界面控件超出父控件位置。
确定self.view 的frame大小,看看addview的frame 大小,再看看btn的frame位置大小,确定一层一层都在self.view的frame内~