简体   繁体   English

为什么移动 UIView 不会在同一视图上移动 UIImageView?

[英]Why moving UIView is not moving UIImageView on same view?

I have an ImageView on a UIView.我在 UIView 上有一个 ImageView。 I'm trying to move view keyboard size but all content move properly instead of UIImageView.我正在尝试移动视图键盘大小,但所有内容都正确移动,而不是 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];
}

Anyone had same issue or some suggestion?任何人有同样的问题或一些建议? I even tried to move UIImage but it is not moving.我什至试图移动 UIImage 但它没有移动。

在此处输入图片说明

As you can see everything moved except imageview!正如你所看到的,除了 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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM