我在 UIView 上有一个 ImageView。我正在尝试移动 View 键盘大小,但所有内容都正确移动,而不是 UIImageView。
-(void) keyboardWillShow:(NSNotification *) notification {
NSDictionary* keyboardInfo = [notification userInfo];
// Work out where the keyboard will be
NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey];
CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue];
// Work out animation duration
NSTimeInterval animationDuration =[[keyboardInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationOptions keyboardAnimationCurve = [[keyboardInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
// Animate this
[UIView animateWithDuration:animationDuration
delay:0.0
options:keyboardAnimationCurve
animations:^(){
self.view.frame = CGRectOffset(self.view.frame, 0, -keyboardFrameBeginRect.size.height);
}
completion:NULL];
[UIImageView animateWithDuration:animationDuration
delay:0.0
options:keyboardAnimationCurve
animations:^(){
self.imgBankLogo.frame = CGRectOffset(self.imgBankLogo.frame, 0, -keyboardFrameBeginRect.size.height);
}
completion:NULL];
}
有人有同样的问题或建议吗?我什至尝试移动 UIImage,但它没有移动。
如您所见,除了 imageview 之外的所有内容都移动了!
最佳答案
如果您尝试将两个 View 一起移动,并且一个 View 是另一个 View 的 subview ,则您不需要单独为它们设置动画。
动画化父 View 应该自动移动所有 subview 。根据我的经验,尝试同时单独为它们制作动画可能会导致奇怪的结果。这个动画 block 应该是你所需要的。您可能还想检查 View 文件检查器选项卡中的自动布局设置。
如果您想一次执行多个动画,您也可以在同一个动画 block 中添加多个调用。
[UIView animateWithDuration:animationDuration
delay:0.0
options:keyboardAnimationCurve
animations:^(){
//you can add multiple here
self.view.frame = CGRectOffset(self.view.frame, 0, -keyboardFrameBeginRect.size.height);
}
completion:NULL];
关于ios - 为什么移动 UIView 不会在同一 View 上移动 UIImageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36392780/