I am using UIView animateWithDuration method to flip the UILabelView itself but it doesn't show any animation until I provide some code in the animations block. Here's the code.
No effect
[UIView animateWithDurations:5. delay:0.
options:UIViewAnimationOPtionTransitionFlipFromLeft animations: ^{}
completion:nil];
Fades the View
[UIView animateWithDurations:5. delay:0.
options:UIViewAnimationOPtionTransitionFlipFromLeft
animations: ^{self.lblEvent.alpha = 0.5;} completion:nil];
My question is when the options parameter will effect?
I tried the below code too but it flips the view and removes from the controller. Can't I provide the same view?
[UIView transitionFromView: self.lblEvent toView:self.lblEvent
duration:2.0 options:UIViewAnimationOPtionTransitionFlipFromLeft
completion:nil];
Try this one:
[UIView transitionWithView:your_view_to_animate duration:1. options:(UIViewAnimationOptionTransitionFlipFromBottom) animations:^{
} completion:^(BOOL finished) {
}];
Good Luck!
Related
I have an app in which I use a lot of animations with ease in/out curves. I use this function in all cases: UIView animateWithDuration:delay:options:animations:completion
All these animations are working ok, but now I am trying to add one to a drawer that pops in and out, and for some reason this particular animation is always linear:
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.activityBar.view.frame = CGRectMake(0, self.activityBar.view.frame.origin.y, self.activityBar.view.frame.size.width, 20);
} completion:nil];
Why is this animation linear, while other animations with the same option are curved?
This is the view hierarchy for self.activityBar.view
-UIViewController
-UIViewController
-UIViewController (animation code lives here)
-UIViewController (activityBar)
-UIView (activityBar.view)
//Set old Frame for activityBar Here
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
[self.view layoutIfNeeded];
//Update to the new frame
self.activityBar.view.frame = CGRectMake(0, self.activityBar.view.frame.origin.y, self.activityBar.view.frame.size.width, 20);
} completion:^(BOOL finished) {
}];
I want an animated UIView that will move like this lever on this image. seesaw but i have no great knowledge on animations in xcode. I can only do sliding like this
[UIView animateWithDuration:1.0 delay:2.0 options:(UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
animations:^
{
[UIView setAnimationDelegate:self];
self.bug.center = CGPointMake(75, 200);
}
completion:^(BOOL finished)
{
NSLog(#"Move to left done");
}
];
Is there a way that i can use manipulate this code and animate it like a seesaw?
I have toolbar on my view and I want to move it with animation, but the animation does not work, the toolbar move quickly to the new position. I use it:
[UIView animateWithDuration:2.0f animations:^{
[self.view layoutIfNeeded];
self.toolbarBottomLayoutConstraint.constant = editing ? 0 : -44;
}];
Does anybody know why?
I've tried just changing animation block sentences and it worked for me:
[UIView animateWithDuration:2.0 animations:^{
self.bottomMargin.constant = editing ? 0 : -44;
[self.view layoutIfNeeded];
}];
Why don't you do something like this?
[UIView animateWithDuration:2.0f
animations:^{
yourView.center = CGPointMake(yourView.frame.size.width/2, -44);
} completion:^(BOOL finished) {}];
Apple's documentation describes UIViewAnimationOptionLayoutSubviews as:
Lay out subviews at commit time so that they are animated along with
their parent.
Here is a sample of the code I'm interested in. I wish to animate the -layoutSubviews of detailView; however, it doesn't seem to layout the subviews of detailView, so I'm not sure what effect it actually has.
void (^animation) () = ^
{
[self.detailView setNeedsLayout];
[self.detailView layoutIfNeeded];
};
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
animation();
}
completion:nil];
Since you want your second animation to occurs from the current state of your first animation (whether it is finished or not) I recommend to use the UIViewAnimationOptionLayoutSubviews option when setting your second animation.
[UIView animateWithDuration:0.2
delay:0.0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
CGAffineTransform settingsTransform = CGAffineTransformMakeTranslation(self.animatedView.frame.size.width, 0);
self.animatedView.transform = settingsTransform;
}
completion:nil];
I'd like to animate the transition from a subview back to the super view.
I display the subview using:
[UIView beginAnimations:#"curlup" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[self.view addSubview:self.mysubview.view];
[UIView commitAnimations];
The above works fine. It's going back to the super view that I don't get any animation:
[UIView beginAnimations:#"curldown" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[self.view removeFromSuperview];
[UIView commitAnimations];
Is there something different I should be doing to get the subview to animate when removed?
If you're targeting iOS 4.0 upwards you can use animation blocks instead:
[UIView animateWithDuration:0.2
animations:^{view.alpha = 0.0;}
completion:^(BOOL finished){ [view removeFromSuperview]; }];
(above code comes from Apple's UIView documentation)
I think you need to do forView:self.view.superview instead, to be consistent with what you are doing when you are adding, because in this case the self.view is the child, and so you would need to do it on the parent.
JosephH answer in Swift:
UIView.animateWithDuration(0.2, animations: {view.alpha = 0.0},
completion: {(value: Bool) in
view.removeFromSuperview()
})
Although approach with sending removeFromSuperview message from animation completion block works fine for most cases, sometimes there is no way to prevent a view from immediate removal from view hierarchy.
For example, MKMapView removes its subviews after it receives message removeAnnotations, and there is no "animated" alternative for this message in the API.
Nonetheless the following code allows you to do whatever you like with a visual clone of a view after it's been removed from superview or even deallocated:
UIView * snapshotView = [view snapshotViewAfterScreenUpdates:NO];
snapshotView.frame = view.frame;
[[view superview] insertSubview:snapshotView aboveSubview:view];
// Calling API function that implicitly triggers removeFromSuperview for view
[mapView removeAnnotation: annotation];
// Safely animate snapshotView and release it when animation is finished
[UIView animateWithDuration:1.0
snapshotView.alpha = 0.0;
}
completion:^(BOOL finished) {
[snapshotView removeFromSuperview];
}];
Example below:
func removeSpinningGear(cell: LocalSongsCollectionViewCell) {
UIView.animate(withDuration: 1.0, delay: 0.0, options: UIView.AnimationOptions.curveLinear, animations: {
cell.spinningGearBtn.alpha = 0.0
}) { _ in
cell.spinningGearBtn.removeFromSuperview()
}
}