Dissolve animation for single view in iOS - ios

I have a view and on that there is a AVPlayer on that I need a dissolve animation when the player is
moving from the first video to second video.

I don't know your UIView structure, but you can load the new UIView / AVVideo and use UIView animations to transform the current view to the second one.
// load new UIView
// make it invisible
[UIView animateWithDuration:1
delay:1.5
options:UIViewAnimationCurveEaseOut
animations:^{
// fade in, or change x/y to slide in
}
completion:^(BOOL finished){
NSLog(#"Done!");
}];

Related

Fading from one view to another without transitioning through black

I am trying to fade one view in while fading the other out using animateWithDuration and changing the alpha values of each. The problem I'm having is that the views seem to fade through a black background. I would like to keep the transitioning background a white color being that both of my views have white backgrounds.
How can I fade between my two views without transitioning through a black background?
Here's my code:
[self.view1 setAlpha:0.0];
[self.view addSubview:self.view1];
[UIView animateWithDuration:0.5
animations:^{self.view1.alpha = 1.0;self.view2.alpha = 0.0;}
completion:^(BOOL finished){[self.view2 removeFromSuperview];}];
How about something like this:
[UIView transitionWithView:self.view
duration:0.4
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.view addSubview:self.view1];
}
completion:^(BOOL finished) {
[self.view2 removeFromSuperview];
}];
Use: animateWithDuration:animations:completion:
Set the new image view alpha to 0.
Place the new image view in front of the current image view.
In animations: set alpha of the new image view to 1.0.
In completion: handler cleanup how ever you want.

Pausing a UIView's key frame animations

I'm currently creating a loading bar that I would like to pause and reverse if a specific action is taken.
I have the following code below that animates one view in another. How would I go about pausing this animation and applying another animation on the CURRENT frame at that point in time for the animated object. I would like to be able to animate this bar down to the 0 width mark at any given time within the current animation.
-(void)animateProgressBar
{
CGRect endingFrame = self.frame;
[UIView animateKeyframesWithDuration:self.time delay:0.0 options:0 animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:1.0 animations:^{
self.loadingBar.frame = endingFrame;
}];
} completion:^(BOOL finished) {
NSLog(#"TADA");
}];
}
If you want to start a new animation from where this one is now, just start the new animation using the the UIViewKeyframeAnimationOptionBeginFromCurrentState option (or if just doing animateWithDuration, use UIViewAnimationOptionBeginFromCurrentState).
You can import QuartzCore framework, add
#import <QuartzCore/QuartzCore.h>
And you can remove existing animation by calling:
[self.loadingBar.layer removeAllAnimations];
After that you can start new animation.
If you want to pause it you have to get reference to the current animation:
CALayer *currentLayer = self.loadingBar.layer.presentationLayer;
And you have to save it:
self.loadingBar.layer.transform = currentLayer.transform;
You can do it in another [UIView animateWith..... method.

How to cross-fade a UIScrollView back to the beginning

I have a horizontally-scrolling paging UIScrollView in an iPad app, containing lots of pages. On the last page, I tap on a button on the screen to reset back to page 1. I would like to be able to cross-dissolve this transition, but it doesn't seem to work:
[UIView transitionWithView:self.view duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationOptionAllowAnimatedContent animations:^{
pagingScrollView.contentOffset = CGPointZero;
} completion:^(BOOL finished) {
[self refreshPages];
}];
I read that adding UIViewAnimationOptionAllowAnimatedContent will allow all content to transition, but it doesn't work. Instead, the screen cross-dissolves to the background colour, and when the transition is complete, the first page just appears.
you cannot fade-out a UIView (the scroller) AND simultaneously fade-in the same view...
you could just using different UIViews...
what you can do is:
1) fadeOut the scroller in the current position (to the backGround)
2) while the scroller is invisible, move it to the right position (with no animation)
3) fadeIn the scroller from the backGround
something like:
// START FIRST PART OF ANIMATION
[UIView animateWithDuration:0.5 delay:0.0 options: options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationOptionAllowAnimatedContent animations:^{
pagingScrollView.alpha = 0;
} completion:^(BOOL finished) {
// FIRST PART ENDED
// MOVE SCROLLER (no animation)
pagingScrollView.contentOffset = CGPointZero;
// START SECOND PART OF ANIMATION
[UIView animateWithDuration:0.5 delay:0.0 options: options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationOptionAllowAnimatedContent animations:^{
// fadeIn - animated
pagingScrollView.alpha = 1;
} completion:^(BOOL finished) {
// ANIMATION ENDED
[self refreshPages];
}];
}];
NEW EDIT:
thanks to amadour, who taught me something with his comments,
i hope he could add an answer of his own, i would vote for him
anyway, to answer to jowie original question:
i got the right animation just moving the contentOffset setting out of the animation block,
and removing UIViewAnimationOptionAllowAnimatedContent (not really needed), and passing pagingScrollView as parameter for transitionWithView
this worked for me:
pagingScrollView.contentOffset = CGPointZero;
[UIView transitionWithView:pagingScrollView duration:3.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
// pagingScrollView.contentOffset = CGPointZero; // move up, outside of animation block
} completion:^(BOOL finished) {
NSLog(#"-->> END amimation");
[self refreshPages];
}];

view intercepts touch before it takes window

Hello in my app i emulated slide view's and use this code
[UIView beginAnimations: nil context:nil];
[UIView setAnimationDuration: 0.5];
[UIView commitAnimations];
unfortunately new view intercepts touch before it takes window : if i make double click,with second click work new view
I check frame of this view it equal frame of window
if i turn off animation it work correct. but i need animation effects
Please help me to find right decision )
Try using blocks for the UIView animation. Initially disable the touch on the new view. Then animate and in completion block, enable the touch.
//disable touch on the slide view
[UIView animateWithDuration:0.5
animations:^{
//.. animate here
}
completion:^(BOOL finished){
//enable touch on the new view
}]

How to resize a view mid-way during a moving animation?

During a sliding animation(down, pause, then up back to the original position) of a subview, the device is rotated, so the superview is rotated. I want to keep the subview's width the same as the superview, so I need to resize it during its sliding animation.
Here is the sliding animation code:
[UIView animateWithDuration:0.3 animations:^{
self.frame = finalFrame;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 delay:3 options:0 animations:^{
self.frame = initFrame;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}];
This is the method that is called when I detect rotation:
- (void)rotate:(NSNotification *)notif {
// What to do here to adjust the width but also keep the sliding animation going.
}
It seems there is no auto-resizing magic that can be used here. One must:
Record the progress of the animations.
On detection of rotations, cancel the old animations, adjust the view size, and add new animations starting from the current progress.
Here is a sample project for reference: http://d.pr/f/M4UW.
You can animate the bounds of the layer to change the width. Just make the height the same and apply an animation for the bounds.
If you want both animations to have the same duration, timing function etc. then you could add them both to an animation group and add that group to the layer you are animating.

Resources