Why moving UIView is not moving UIImageView on sam

2019-08-10 01:16发布

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.

enter image description here

As you can see everything moved except imageview!

enter image description here

1条回答
等我变得足够好
2楼-- · 2019-08-10 01:47

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];
查看更多
登录 后发表回答