为什么移动 UIView 不会在同一视图上移动 UIImageView? [英] Why moving UIView is not moving UIImageView on same view?

查看:30
本文介绍了为什么移动 UIView 不会在同一视图上移动 UIImageView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UIView 上有一个 ImageView.我正在尝试移动视图键盘大小,但所有内容都正确移动,而不是 UIImageView.

I have an ImageView on a UIView. I'm trying to move view keyboard size but all content move properly instead of 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 但它没有移动.

Anyone had same issue or some suggestion? I even tried to move UIImage but it is not moving.

正如你所看到的,除了 imageview 之外,所有东西都被移动了!

As you can see everything moved except imageview!

推荐答案

如果您尝试将两个视图移动到一起,并且一个是另一个的子视图,则不需要单独为它们设置动画.

If you are trying to move two views together, and one is a subview of the other, you shouldn't need to animate them individually.

动画父视图应该自动移动所有子视图.根据我的经验,尝试同时单独为它们设置动画可能会导致奇怪的结果.这个动画块应该就是你所需要的.您可能还想检查视图文件检查器选项卡中的自动布局设置.

Animating the parent view should move all of the subviews with it automatically. Trying to animate them individually at the same time can cause weird results in my experience. This animation block should be all you need. You may also want to check the Auto Layout settings in the views File Inspector tab.

如果您想一次执行多个动画,您也可以在同一个动画块中添加多个调用.

If you want to perform more than one animation at once you can add multiple calls in the same animation block as well.

[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];

这篇关于为什么移动 UIView 不会在同一视图上移动 UIImageView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆