动画我的自定义数字键盘

时间:2010-01-13 07:54:13

标签: iphone objective-c

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

我有一个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”显示为子视图,它没有将“animate”效果作为默认数字键盘,如何使其“动画”出现?

2 个答案:

答案 0 :(得分: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;
}

答案 1 :(得分:0)

- (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;
}