Heim > Fragen und Antworten > Hauptteil
/*这段代码功能是添加按钮,视图上移,但是发现在上移的视图里,添加的按钮不响应,这是为什么呢?*/
-(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");
}
天蓬老师2017-04-17 18:01:40
界面控件超出父控件位置。
确定self.view 的frame大小,看看addview的frame 大小,再看看btn的frame位置大小,确定一层一层都在self.view的frame内~
高洛峰2017-04-17 18:01:40
看不懂你想写什么,不过 UIView *addView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREENSIZE.height,SCREENSIZE.width, 80)];的frme的Y和高,设置错了吧,调换一下就可以点了