iOS 修改fram无效问题

用auto layout写了一个键盘出现时候,视图自动缩进的demo,成功了,但是同样的代码实现在另外一个工程上面就有问题了,问题来源于第一次的时候,修改view的frame成功了,但是没有动静,查看控制台修改成功了,但是下一次再修改的时候,它居然没有修改到,这个是为什么?

控制台输出:x,y,height,width ,两个视图需要修改,第一个改y,第二个改height
第一次修改前:
2015-05-17 17:19:15.266 ICU[3841:117974] 0.000000,**617.000000**,50.000000,375.000000
2015-05-17 17:19:15.266 ICU[3841:117974] 0.000000,69.000000,**540.000000**,375.000000
修改后:
2015-05-17 17:19:15.267 ICU[3841:117974] 0.000000,**397.000000**,50.000000,375.000000
2015-05-17 17:19:15.267 ICU[3841:117974] 0.000000,69.000000,**320.000000,**375.000000

第二次修改前:
2015-05-17 17:19:30.841 ICU[3841:117974] 0.000000,617.000000,50.000000,375.000000
2015-05-17 17:19:30.841 ICU[3841:117974] 0.000000,69.000000,540.000000,375.000000

修改后:
2015-05-17 17:19:30.842 ICU[3841:117974] 0.000000,364.000000,50.000000,375.000000
2015-05-17 17:19:30.842 ICU[3841:117974] 0.000000,69.000000,287.000000,375.000000

代码如下:

#pragma mark KeyBoard Event Function
//当键盘出现的时候,修改footview的位置和collectionview的高度
//$$ 方法未达到预期效果
-(void)keyboardWillAppear:(NSNotification*) notification{
NSLog(@"%f,%f,%f,%f",self.FootView.frame.origin.x,self.FootView.frame.origin.y,self.FootView.frame.size.height,self.FootView.frame.size.width);
NSLog(@"%f,%f,%f,%f",self.messageCollectionView.frame.origin.x,self.messageCollectionView.frame.origin.y,self.messageCollectionView.frame.size.height,self.messageCollectionView.frame.size.width);

[UIView setAnimationDuration:0.3];
NSDictionary* userDict = [notification userInfo];

NSValue* keyBoardValue = [userDict objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyBoardRect = [keyBoardValue CGRectValue];
int keyboardY = keyBoardRect.origin.y;

if (self.FootView == nil || self.messageCollectionView == nil) {
NSLog(@"NULL");
}

//Set the footView Size
CGRect footViewRect = self.FootView.frame;
CGRect contentRect = self.messageCollectionView.frame;

//Set CollectionView Size
footViewRect.origin.y = keyboardY - footViewRect.size.height + 5;
self.FootView.frame = footViewRect;
contentRect.size.height = footViewRect.origin.y - contentRect.origin.y - 8;
self.messageCollectionView.frame = contentRect;

[UIView commitAnimations];

NSLog(@"%f,%f,%f,%f",self.FootView.frame.origin.x,self.FootView.frame.origin.y,self.FootView.frame.size.height,self.FootView.frame.size.width);
NSLog(@"%f,%f,%f,%f",self.messageCollectionView.frame.origin.x,self.messageCollectionView.frame.origin.y,self.messageCollectionView.frame.size.height,self.messageCollectionView.frame.size.width);
}

//当键盘消失的时候,恢复footview的位置和collectionview的高度
//$$ 方法未达到预期效果
-(void)keyboardWillDisapper:(NSNotification*)Notification{
[UIView setAnimationDuration:0.3];

CGRect footViewRect = self.FootView.frame;
footViewRect.origin.y = self.view.frame.size.height - footViewRect.size.height;
self.FootView.frame = footViewRect;

CGRect messageRect = self.messageCollectionView.frame;
messageRect.size.height = footViewRect.origin.y -messageRect.origin.y - 8;
self.messageCollectionView.frame = messageRect;

[UIView commitAnimations];

}

各位大大,解答一下我的问题吧,谢谢了

ios

1个回答

在第二次修改之前需要将第一次修改的frame修改回去

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐