【发布时间】:2015-03-29 11:36:53
【问题描述】:
当键盘启动时尝试为按钮设置动画时,我遇到了 [UIView animationWithDuration] 的问题。我有一个通知告诉我键盘何时出现,然后我让 ViewController 在视图中调用此方法。按钮动画但不正确。它只是从屏幕上的随机位置动画到之前的位置。我再次提出这个问题的原因是因为我已经看到其他帖子的答案说在 ViewController 中将视图的 translatesAutoresizingMaskIntoConstraints 属性设置为 YES 可以解决问题,但不能解决问题。
[self.view setTranslatesAutoresizingMaskIntoConstraints:YES];
动画如下:
- (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)];
}];
}
有人知道发生了什么吗?提前致谢。
【问题讨论】:
-
你使用自动布局吗?如果是这样,您最好在动画块中设置
NSLayoutConstraint的constant属性。然后调用updateConstraintsIfNeeded。 -
如果您不使用
Autoloayout,则没有理由使用setTranslatesAutoresizingMaskIntoConstraints:。你在哪里打电话给animateForKeyboardAppearanceWithKeyboardSize:? -
我没有使用笔尖,所以我认为这不适用于这里。不过感谢您的回复。
-
当收到键盘即将出现的通知时,我在视图控制器中调用
animateForKeyboardAppearanceWithKeyboardSize:。- (void)keyboardWillShow:(NSNotification *)notification { NSDictionary *userInfo = [notification userInfo]; CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; [self.createAccountView animateForKeyboardAppearanceWithKeyboardSize:keyboardSize]; } -
一旦你弄清楚了这一点,你可能想看看这里找到的一些想法来改进你的动画。 stackoverflow.com/questions/18837166/…
标签: ios objective-c xcode animation ios8