Make textfield appear from above in an animated way iphone sdk
Hi Friends I am using the code is
- (BOOL)textFieldShouldReturn:(UITextField *) sender
{
appDelegateObj.plogoImgView.hidden=NO;
[sender resignFirstResponder];
if (verticalOffset!=0)
{
[self moveView: -verticalOffset];
verticalOffset = 0;
}
return TRUE;
}
- (void)textFieldDidBeginEditing:(UITextField *)theTextField
{
appDelegateObj.plogoImgView.hidden=YES;
int wantedOffset;
if(theTextField.tag==10)
wantedOffset = theTextField.frame.origin.y - 50;
else
{
wantedOffset = theTextField.frame.origin.y - 150;
}
if ( wantedOffset < 0 )
{
wantedOffset = 0;
}
if ( wantedOffset != verticalOffset )
{
[self moveView: wantedOffset - verticalOffset];
verticalOffset = wantedOffset;
}
}
- (void)moveView:(int)offset
{
[UIView beginAnim开发者_JS百科ations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect rect = self.view.frame;
rect.origin.y -= offset;
self.view.frame = rect;
[UIView commitAnimations];
}
My problem is the above code is working but in device whenever view will appear method called its not working how to write view will appear please tell me.
Thanks in advance..
I don't really get everything from your question, but i'll give it a go.
So you say:
problem is the above code is working but in device whenever view will appear method called its not working how to write view will appear please tell me.
Do you mean that the code is working in some tutorial you saw it in or is it working in your simulator and not on the device?
Seems odd to me that some animation code would work in simulator but not on the device, so that should not me the problem.
You're talking about viewWillAppear not being called, are you using a navigation controller? In a navigation controller based app the viewWillAppear method won't get called.
The methods you are using to show and hide the desired keyboard are also a little bit weird, you talk about animating an UITextField in, but you are moving the whole view?
Why don't you just create a property for the desired textfield or at least an instance variable, so you can address that textfield from any method to animate it in/out.
If you are using a nivation controller: Create a method and call it something like "moveTextFieldIn", then in the previous viewController you will probably have something like this:
UIViewController * nextViewController = [[UIViewController alloc] init];
[[self navigationController] pushViewController:nextViewController animated:YES];
[nextViewController release];
Change that to this:
UIViewController * nextViewController = [[UIViewController alloc] init];
[nextViewController moveTextFieldIn];
[[self navigationController] pushViewController:nextViewController animated:YES];
[nextViewController release];
Or to this (if you're not creating moveTextFieldIn):
UIViewController * nextViewController = [[UIViewController alloc] init];
[nextViewController viewWillAppear];
[[self navigationController] pushViewController:nextViewController animated:YES];
[nextViewController release];
Well, lot's of guesses, but I hope this will be help you!
One more thing: The standard animation duration is 0.3, so you can delete that line of code, keep it clean ;-)
精彩评论