ios - 为什么移动 UIView 不会在同一 View 上移动 UIImageView?

标签 ios objective-c uiview uiimageview

我在 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,但它没有移动。

enter image description here

如您所见,除了 imageview 之外的所有内容都移动了!

enter image description here

最佳答案

如果您尝试将两个 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/

相关文章:

objective-c - 如何在 objective-c 中移动图像

php - 仅收到第一个推送通知 PHP

objective-c - iOS7自定义交互转场,隐藏的后退按钮取消时重新出现为 "..."

iphone - 将当前 View 替换为任何现有的新 View

ios - 如何在 iOS 中平滑地放大和缩小 UIButton

ios - 有什么方法可以让 "Validate Project Settings"警告在 Xcode 4.3/4.3.1 中消失?

ios - 覆盖 super View 中元素的大小?

objective-c - iOS Native App 中的拇指识别

ios - 标签高度错误

iphone - 从 uiview 中删除所有对象?