简体   繁体   中英

UIView animateWithDuration… not working in iOS 8

I have a problem with [UIView animationWithDuration] when trying to animate a button when the keyboard come up. I have a notification tell me when the keyboard comes up then I have the ViewController call this method in the view. The button animates but not correctly. It just animates from a random position on the screen to the position it was at previously. The reason I bring this up again is because I've seen answers from other posts saying that setting the view's translatesAutoresizingMaskIntoConstraints property to YES in the ViewController will fix the problem, but it doesn't fix the problem.

    [self.view setTranslatesAutoresizingMaskIntoConstraints:YES];

The animation is below:

- (void)animateForKeyboardAppearanceWithKeyboardSize:(CGSize)keyboardSize; {
    [UIView animateWithDuration:0.3f
                 animations:^{
                     [self.sendSMSButton setFrame:CGRectMake(0,
                                                             self.frame.size.height - keyboardSize.height - self.sendSMSButton.frame.size.height,
                                                             self.frame.size.width,
                                                             self.sendSMSButton.frame.size.height)];
                 }];
}

Anyone know what's happening? Thanks in advance.

Have you ensured that this method isn't being called repeatedly? Also try subclassing the button, override -setFrame and double check to see if something else is setting the frame of your button while you are trying to animate it.

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