/*这段代码功能是添加按钮,视图上移,但是发现在上移的视图里,添加的按钮不响应,这是为什么呢?*/
-(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內~
是的,addview超出了範圍,使用動畫的物件不對。多謝。
看不懂你想寫什麼,但UIView *addView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREENSIZE.height,SCREENSIZE.width, 80)];的frme的Y和高,設定錯了吧,調換一下就可以點了
UIView是需要添加交互效果的,默认是不能接到点击效果
,把接受點擊效果的屬性設定成YES就搞定要嘛是超出父控制範圍 要嘛是父控制項的互動不允許
如果你非要互動的話也有方法
自訂一個不規則的父視圖(問這問題估計你不會)
在view的觸碰事件中 重新定義相對父視圖的位置