ios - 如何水平/从左到右设置动画?

标签 ios animation

垂直动画没有问题,但是我必须对水平动画的值做什么?即使是苹果指南中的内置动画也没有提供任何水平动画的引用。垂直覆盖即可。使用 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/

相关文章:

ios - UIWebView loadRequest复用给出闪烁效果

jquery - 如何在悬停时创建显示图像动画效果?

ios - 阻止 UIButton 的 setTitle :forState: animation

javascript - Canvas 动画像素化

ios - 通过谷歌账户登录iOS应用并返回应用

ios - objective c 在 textField 操作后将光标移回

ios - 以编程方式使用 NSTimer 更新 UILabel 文本

ios - iOS 应用程序使用 Web 服务需要不同的框架

javascript - 使用 Jquery 仅在选中时为一个元素设置动画

jquery - 单击实际元素以启动动画