I create my own number pad view successfully and I want to simulate the default number pad appear animated effect, but it can't work fine, it can't animate as default number pad, how do I modify?
I have a UITextField call "fNumber" and a custom number pad view call myNumberPadView and created by interface builder, when the "fNumber" is focued I will show the myNumberPadView animated, so I code as follow:
- (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;
}
The "myNu开发者_如何转开发mberPadView" is show as a subview, it doesn't the "animate" effect as the default number pad, how can to make it to "animate" appear?
in the animation block, just set the new frame to your custom numpad. smth like
- (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; }
- (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;
}
精彩评论