【问题标题】:animate my custom number pad为我的自定义数字键盘设置动画
【发布时间】:2010-01-13 07:54:13
【问题描述】:

我创建自己的数字键盘视图成功,我想模拟默认数字键盘出现动画效果,但是不能正常工作,不能动画为默认数字键盘,我该如何修改?

我有一个 UITextField 调用“fNumber”和一个自定义数字键盘视图调用 myNumberPadView 并由界面生成器创建,当“fNumber”被聚焦时,我将显示 myNumberPadView 动画,所以我的代码如下:


 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField == fNumber){
        CGRect frame = CGRectMake(0, 270, 320, 230);
        myNumberPadView.frame = frame;
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.75];
        frame.origin.x = 0;
        frame.origin.y = 270; 
        [UIView commitAnimations];
        [self.view addSubview:myNumberPadView];
    }
    return NO;
}

“myNumberPadView”显示为子视图,它没有“动画”效果作为默认数字键盘,如何使其“动画”出现?

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    在动画块中,只需将新帧设置为您的自定义数字键盘。喜欢

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
        if (textField == fNumber){
            CGRect frame = CGRectMake(0, 480, 320, 230);
            [myNumberPadView setFrame:frame];
            [self.view addSubview:myNumberPadView];
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:1.75];
            [myNumberPadView setFrame:CGRectMake(0, 270, 320, 230)]; 
            [UIView commitAnimations];
        }
        return NO;
    }
    

    【讨论】:

    • 莫里安说得对。在屏幕下方看不到的地方添加子视图,然后启动一个动画块,将视图上的框架设置到它应该结束的位置,然后提交动画。这将使它顺利地从一个位置移动到另一个位置。
    【解决方案2】:
    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField == fNumber){
        CGRect frame = CGRectMake(0, 270, 320, 230);
        myNumberPadView.frame = frame;
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.75];
        frame.origin.x = 0;
        frame.origin.y = 270; 
       // [UIView commitAnimations];
        [self.view addSubview:myNumberPadView];//Place this before the line  [UIView commitAnimations];
        [UIView commitAnimations];
    }
    return NO;
    }
    

    【讨论】:

      猜你喜欢
      • 2015-11-10
      • 1970-01-01
      • 1970-01-01
      • 2016-02-03
      • 1970-01-01
      • 2012-05-21
      • 2021-05-07
      • 1970-01-01
      • 2016-03-28
      相关资源
      最近更新 更多