简体   繁体   中英

Why moving UIView is not moving UIImageView on same view?

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

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

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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