/*这段代码功能是添加按钮,视图上移,但是发现在上移的视图里,添加的按钮不响应,这是为什么呢?*/
-(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");
}
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
UIView是需要添加交互效果的,默认是不能接到点击效果
, set the attribute that accepts click effects to YES and you’re doneEither 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
Customize an irregular parent view (I guess you don’t know how to ask this question)
Redefine the position relative to the parent view in the touch event of the view