I have app i want that when user enters any data then view should slide up.
I am writing this code this code works fine in another app but not working in this app.I am following same way.
-(void)showAnimationBack{
NSLog(#"Back Animation is Working");
[UIView animateWithDuration:0.5
animations:^{
self.subViewLand.frame = CGRectMake(0,-10,1024,768);
}];
}
-(void) showAnimationPests{
NSLog(#" Animation is Working");
[UIView animateWithDuration:0.5
animations:^{
self.subViewLand.frame = CGRectMake(0,-200,1024,768);
}];
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
self.subViewLand.frame = CGRectMake(0,-200,1024,768); // or to self.view.frame = CGRectMake(0,-200,1024,768);
[UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
self.subViewLand.frame = CGRectMake(0,-200,1024,768); // or to self.view.frame = CGRectMake(0,-200,1024,768);
[UIView commitAnimations];
}
This code will work
in textfielddidBeginEditing Method set view frame like this
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self.subViewLand setFrame:CGRectMake(0, -200, 320, 480)];
}
in textfielddidEndEditing Method set view frame as it is.
- (void)textFieldDidEndEditing:(UITextField *)textField{
[self.subViewLand setFrame:CGRectMake(0, 0, 320, 480)];
}
It will definitely work. :)
In textFieldDidBeginEditing() call the your method showAnimationPests() and similarly in textFieldDidEndEditing() call showAnimationBack() .
This will work fine for you.
Related
Update, SOLVED
Sorry for my english, but i will do my best.
I have a problem with a button flip animation.
I want the UIButtons to fill the UIView. But how do i do that?
Here is my problem.
I have two UIButtons in a UIView.
When i press the first button it will flip correctly but when i press the second button that it have flipped to the UIView is still the same size but the UIButton image is changing size to the original size of the image and it also move the image to the upper left corner off the view controller. The same thing will repeat every time it flip.
Here is the flip animation code.
- (IBAction) buttonPressedFlip {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
if (flipState == 0) {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:buttonContainer cache:YES];
[self.btn1 removeFromSuperview];
[buttonContainer addSubview:btn2];
flipState = 1;
}
else {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:buttonContainer cache:YES];
[self.btn2 removeFromSuperview];
[buttonContainer addSubview:btn1];
flipState = 0;
}
[UIView commitAnimations];
}
Have a nice day and thanks for any help!
I solved the problem like this
- (IBAction) buttonPressedFlip {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
if (flipState == 0) {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:buttonContainer cache:YES];
[self.buttonContainer bringSubviewToFront:btn2];
flipState = 1;
}
else {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:buttonContainer cache:YES];
[self.buttonContainer bringSubviewToFront:btn1];
flipState = 0;
}
[UIView commitAnimations];
}
I solved the problem
See my update code.
I have a UIView animation bringing a UIView from the left onto the screen, the method is being triggered so quickly in rapid succession from the bar code scanning engine that the method is being triggered then triggered again so it goes back off of the screen.
-(IBAction)showDetailModeView
{
if (detailModeViewON==FALSE)
{
[UIView beginAnimations:#"move buttons" context:nil];
[UIView setAnimationDuration:.3];
[detailModeView setFrame:CGRectMake(0, 0, 320, 568)];
[UIView commitAnimations];
detailModeViewON=TRUE;
}
else
{
[UIView beginAnimations:#"move buttons" context:nil];
[UIView setAnimationDuration:.3];
[detailModeView setFrame:CGRectMake(-320, 0, 320, 568)];
[UIView commitAnimations];
[self stopScanning];
scannedONCE = FALSE;
detailModeViewON=FALSE;
}
[self.view endEditing:YES];
}
is there some way I can basically say if this method was called within the last 5 seconds, don't do anything.
pseudo code
-(IBAction)showDetailModeView
{
if(UIVIEW animation was triggered longer than 5 seconds ago)
{
if (detailModeViewON==FALSE)
{
[UIView beginAnimations:#"move buttons" context:nil];
[UIView setAnimationDuration:.3];
[detailModeView setFrame:CGRectMake(0, 0, 320, 568)];
[UIView commitAnimations];
detailModeViewON=TRUE;
}
else
{
[UIView beginAnimations:#"move buttons" context:nil];
[UIView setAnimationDuration:.3];
[detailModeView setFrame:CGRectMake(-320, 0, 320, 568)];
[UIView commitAnimations];
[self stopScanning];
scannedONCE = FALSE;
detailModeViewON=FALSE;
}
[self.view endEditing:YES];
}
}
Edited to add that you should be using block based animations such as;
[UIView animateWithDuration:(NSTimeInterval)duration
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion];
You can find a lot of examples of this around here.
A lot of the time you need to disallow a transition while one is happening. set the gesture.enabled to NO, for example, and back to YES in the animation's completion block, or use a boolean that you set to NO before the animation begins and set it back to YES in the completion block. Then have a check to see what that boolean is before calling the animation.
These kinds of things are very common in UI implementation. Otherwise you can end up with a lot of multiple firings like you are experiencing.
im trying to do an animation on UIPicker where when my app runs its hidden and when the button is pressed it will appear sliding from the buttom and when i tap the button again it will slide away. well, my code does that but only just once.
it does:
first click -> show the picker, isPickerHidden = NO
second click -> hides picker, isPickerHidden = YES
third click -> does not do anything, but it returns isPickerHidden = NO
where in viewDidLoad declaration are;
and same as the fourth click it doesnt do anything but return the correct BOOL value.
isPickerHidden = YES;
[self.picker setHidden:isPickerHidden];
if(isPickerHidden == NO){
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.6];
CGRect frame = self.picker.frame;
[self.picker setFrame:CGRectOffset(frame, self.picker.frame.origin.x, self.picker.frame.origin.y)];
[UIView commitAnimations];
isPickerHidden = YES;
NSLog(#"hidden yes");
}else if(isPickerHidden == YES) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.6];
CGAffineTransform transfrom = CGAffineTransformMakeTranslation(0, -200);
self.picker.transform = transfrom;
[self.picker setHidden:NO];
[UIView commitAnimations];
NSLog(#"hidden no ");
isPickerHidden = NO;
}
i would like to know on whats the problem i am facing, and what am i missing. thanx
add some logging for the frame and picker to see what is happening...
NSLog(#"picker: %.0f, %.0f, %.0f, %.0f", self.picker.frame.origin.x, self.picker.frame.origin.y, self.picker.frame.size.width, self.picker.frame.size.height);
thanx NS bro for the reply but i did a different approach now instead of offsetting the points from the original one i used CGRectMake, i did this
if(isPickerHidden == NO) {
CGRect frame = self.picker.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.6];
[self.picker setFrame:CGRectMake(frame.origin.x, frame.origin.y + 216, frame.size.width, frame.size.height)];
[UIView commitAnimations];
isPickerHidden = YES;
} else if (isPickerHidden == YES) {
CGRect frame = self.picker.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.6];
[self.picker setFrame:CGRectMake(frame.origin.x, frame.origin.y - 216, frame.size.width, frame.size.height)];
[UIView commitAnimations];
isPickerHidden = NO;
}
both the sliding down and sliding up are doing well animated in the same manner. but now the problem is i wanted to make the UIPicker disappear on app load so in the viewDidLoad i did try to use the [self.picker setHidden:YES]; but the frames i made using CGRect dont appear when i press the button and i also tried alpha still nop.
i did also put in the body of the if-else statement the setHidden to yes and to know with respect to their values.
would like to know what im missing now.
In my program I use the following code to animate the self.view due to the soft keyboard covering up a UITextField at the bottom of the page.
- (IBAction)moveViewUp:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.view.frame = CGRectMake(0,-150,320,400);
[UIView commitAnimations];
}
And the following code brings the view back to original position.
- (IBAction)moveViewDown:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.view.frame = CGRectMake(0,0,320,400);
[UIView commitAnimations];
}
But once both methods are executed, the screen looks very normal though, a UIButton in the screen stops capturing any touches on it.
Any tips would be highly appreciated.
I am use this code when a cell is tapped in an uitableview that exists inside an uiview but is not doing the "flash" that is supposed to do on the cell when the user taps it.
-(IBAction)labelTap:(UIGestureRecognizer *)sender
{
if(sender.state != UIGestureRecognizerStateRecognized)
return;
UIView *tappedview=[sender.view hitTest:[sender locationInView:sender.view]
withEvent:nil];
UIView *contentview1=tappedview.superview.superview;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[contentview1 setAlpha:0];
[contentview1 setAlpha:1];
[UIView commitAnimations];
}
Any help appreciated.
Try this is working!
UIView *contentview1=tappedview.superview;
[contentview1 setAlpha:0];
[UIView animateWithDuration:0.3f
animations:^(void)
{
// Animate the flash on tap
[contentview1 setAlpha:1];
}
completion:^(BOOL finished)
{
NSLog(#"Done! Now show the pop up");
)];