简体   繁体   English

UIView animateWithDuration…在iOS 8中不起作用

[英]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. 尝试在键盘启动时为按钮设置动画时,[UIView animationWithDuration]出现问题。 I have a notification tell me when the keyboard comes up then I have the ViewController call this method in the view. 我有一个通知告诉我键盘何时启动,然后ViewController在视图中调用此方法。 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. 我再次提出此问题的原因是,我从其他帖子中看到了答案,即在ViewController中将视图的translationsAutoresizingMaskIntoConstraints属性设置为YES可以解决问题,但不能解决问题。

    [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. 也可以尝试对按钮进行子类化,覆盖-setFrame并仔细检查以查看是否在设置动画效果时其他设置了按钮的框架。

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

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