垂直动画没有问题,但是我必须对水平动画的值做什么?即使是苹果指南中的内置动画也没有提供任何水平动画的引用。垂直覆盖即可。使用 Objective-C 在 XCode 5 中为 iOS 进行编码。谢谢!
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField == self.passwordTextField) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.4];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 40), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
- (void)textFieldDidEndEditing:(UITextField *)textField
{
if (textField == self.passwordTextField) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.4];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 40), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
最佳答案
self.view.frame = CGRectMake(
self.view.frame.origin.x - 20,
self.view.frame.origin.y - 40,
self.view.frame.size.width,
self.view.frame.size.height
);
然后,您将向左移动 X 20 像素
关于ios - 如何水平/从左到右设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20197269/