Im trying to animate a UIView with this code:
[self.view bringSubviewToFront:RegNrView];
[UIView animateWithDuration:.5 animations:^{
RegNrView.frame = CGRectMake(0, 0, 320, 460);
}
completion:^(BOOL finished) {
}];
The RegNrView is a UIView containing a UITextField and has the frame: (320,0,320,460).
This is called from an IBAction. The first call nothing happens, but the second time it works. Why does it do that?
Related
I have a button and in the button action I want to show my UITableView by sliding from the button and after the cell click it should goest up by sliding effect.I did it by UIViewAnimation by setting the fixed y position and changing the height from 0 to the height
tableview.hidden=FALSE;
tableview.frame = CGRectMake(0,myButton.frame.size.height,myButton.frame.size.width, 0);
[UIView animateWithDuration:AnimationTime animations:^{
tableview.frame = CGRectMake(tableview.frame.origin.x, tableview.frame.origin.x, tableview.frame.size.width, 200 );
} completion:^(BOOL finished) {
}];
But this is not .I wanted a sliding effect.Any help will be appreciable
Use this method for animation. Provide a option for animation style. There a lot of option in objective-c for animation style
[UIView animateWithDuration:15.0f delay:0.0f options:UIViewAnimationOptions animations:^{
tableview.frame = CGRectMake(tableview.frame.origin.x, tableview.frame.origin.x, tableview.frame.size.width, 200 );
} completion:^(BOOL finished)
{
}];
for your case i thought you should use UIViewAnimationOptionTransitionFlipFromTop as animation options for slide table from top to bottom.By using this your table view get its full height in 15 sec. you can mange that too.
EDIT:
Once you clicked on cell, you want that your tableview goes up with slide effect. Than use
[UIView animateWithDuration:2.0f delay:0.0f options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
tableview.frame = CGRectMake(tableview.frame.origin.x, tableview.frame.origin.x, tableview.frame.size.width, 0 );
} completion:^(BOOL finished)
{
}];
for slide up animation.
Problem is not animation, problem is the frame you are defining. Easiest way to do this, is to define open and close frame and use them to animate.. See below..
Define Open and Close frame
-(void)initComponents{
CGRect rect=tableView.frame;
rect.origin=myButton.center;
openFrame=rect;//Assign openFrame before changing the size.
rect.size=CGSizeZero;
tableView.frame=rect;
closeFrame=rect;//Assign closeFrame
}
Call the initComponents function in viewDidLoad to set the initial state of your tableview. Now simply use the functions below on actions where you want to call.
-(void)openMenu{
[UIView animateWithDuration:.3 animations:^{
tableView.frame=openFrame;
}];
}
-(void)closeMenu{
[UIView animateWithDuration:.3 animations:^{
tableView.frame=closeFrame;
}];
}
Thats it. It should work.
Let me know. Cheers.
I'm trying to do a simple animate of a UIView and the problem is that the view doesn't expand/collapse as I want it to do, it only snaps to the end of the animation without moving there. Here is my code:
- (IBAction)policeReportedChanged:(id)sender {
if (self.policeReportedSwitch.isOn) {
[self.policeReportNumberColl setHidden:NO];
[UIView animateWithDuration:1.0f
animations:^
{
[self.policeReportNumberColl setFrame:CGRectMake(0, 130, 320, 65)];
[self.damageView setFrame:CGRectMake(0, 200, 320, 200)];
}
completion:^(BOOL finished)
{
}
];
} else {
[UIView animateWithDuration:1.0f
animations:^
{
[self.policeReportNumberColl setFrame:CGRectMake(0, 0, 0, 0)];
[self.damageView setFrame:CGRectMake(0, 135, 320, 200)];
}
completion:^(BOOL finished)
{
[self.policeReportNumberColl setHidden:YES];
}
];
}
I have set the animation to reveal the UIView policeReportNumberColl when the switch is turned on and collapsed when it isn't. damageView is a UIView below that should move up or down to take the space where the revealed view are or not. Inside policeReportNumberColl are one UILabel and one UITextfield.
I have checked around a lot but can't find anything other than this should work.
EDIT:
I have played around a bit and figured out that it has something to to with which object is sending the action. It DOES work it I connect the animation to a Touch up inside on a UIButton but it does NOT work if I use on Value Changed on my UISwitch like I want to. See code below:
//Does work
- (IBAction) buttonClicked
{
[UIView animateWithDuration:1.0f
animations:^
{
[self.damageView setFrame:CGRectMake(0, 0, 0, 0)];
}
completion:^(BOOL finished)
{
NSLog(#"Klar");
}
];
}
//Does NOT Work
- (IBAction)switchValueChanged {
[UIView animateWithDuration:1.0f
animations:^
{
[self.damageView setFrame:CGRectMake(0, 0, 0, 0)];
}
completion:^(BOOL finished)
{
NSLog(#"Klar");
}
];
}
Does anyone have any idea how to do this on a UISwitch onValueChanged?
Im creating a custom view, it contains methods like Refresh,*LayoutSubviews*, following this tutorial
I want a label to be animated growing, to it's full width and then back to 0 width. Im using this code in "refresh" method:
[UIView animateWithDuration:1.3 animations:^{
CGRect frame = CGRectMake(50, 15, 140, 20);
[labelFav setFrame:frame];
} completion:^(BOOL finished) {
//[labelFav setHidden:YES];
[UIView animateWithDuration:1.3 animations:^{
CGRect frame = CGRectMake(50, 15, 0, 20);
[labelFav setFrame:frame];
}];
}];
The code works on any other view, but since this is a Custom view by some reason the completion block is not executing.
What happens is that it only does the first block. I set a breakpoint in the "completion" block and it stops there but the animation doesnt happen. I tried to setHidden the label and still it doesnt happen.
Any ideas?
remove auto layout from you Interface builder main screen.
your view may be changing it's frame, but auto layout is (possibly) forcing it elsewhere...
Another way to solve problem. Tested.
[UIView animateWithDuration:1.3 animations:^{
CGRect frame = CGRectMake(50, 15, 140, 20);
[labelViewForFav setFrame:frame];
} completion:^(BOOL finished) {
[UIView animateWithDuration:1.3 animations:^{
CGRect frame = CGRectMake(50, 15, 0, 20);
[labelViewForFav setFrame:frame];
} completion:^(BOOL finished) {
}];
}];
Problem is When you make UIlabel width less than its current width. Animation is not done properly. Animation not visible just jump to final frame.
to solve it Put your label in a view change the size of this view and it will work properly.
I have a screen with several buttons from top to bottom and when they touched, they will show pickerview and uidatepicker. the problem is how to scroll the view if uidatepicker blocked the button.
so i want scroll view working here just like when uikeyboard appear. thanks! :)
ps: i really want to upload the images but my reput don't allow me to do that :)
update:
in the end i use this on my code and the animation looks similar with tpavoiding scroll, here is the code
[UIView animateWithDuration: 0.5f animations:^{
self.containerView.frame=CGRectMake(0, -120, 320, 308);
}
completion:^(BOOL finished) {} ];
so containerView will move up 120, and when i click done(toolbar above the uidatepicker) i just make it to normal position.
[UIView animateWithDuration: 0.5f animations:^{
self.containerView.frame=CGRectMake(0, 0, 320, 308);
}
completion:^(BOOL finished) {} ];
Use UIView animations:
[UIView animateWithDuration: duration animations:^{ myView.frame = CGRectMake(0, 0, 320, 320);} completion:^(BOOL finished) { [self doSomething]; } ];
My program has a UIToolBar which contains a UITextField and a UIButton. The whole view (self.view) goes when the soft keypad comes up. As the UIToolBar is moved to a new position, the button sometimes doesn't capture events properly. Several clicks on the button is required to fire a single event.
The following set of code is executed when the keyboard comes up
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.view.frame = CGRectMake(0,-220,320,400);
tableView.frame = CGRectMake(10, 220, 320, 264);
[UIView commitAnimations];
Try this
[UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
self.view.frame = CGRectMake(0,-220,320,400);
tableView.frame = CGRectMake(10, 220, 320, 264);
}completion:^(BOOL finished) {}];