I have a viewcontroller and childView add the viewcontroller.
if the childView add animation and stratAinmation:
[UIView animateWithDuration:1.0f animations:^{
} completion:^(BOOL finished) {
}];
Question:
system animation (page goes down) not smooth whendismissviewcontrolleranimated
if the childView add animation but don't stratAinmation:
system animation is very smooth whendismissviewcontrolleranimated
My plan:
I trychildViewremoveAllAnimation when viewWillDisappear,the animation not smooth too.
help me,thanks.
Related
I have a UIView drawn in Storyboard which holds some buttons and which is called viewHolder.
I get a higher position rectForAnimationBefore
and a lower position rectForAnimationAfter
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:nil completion:^(BOOL finish){
[self.viewHolder setFrame:rectForAnimationAfter];
}];
when this is excuted,the viewHolder do move down.After a second,it comes up as nothing was done.
I want to moveDown,but don't want moveUp Automatically.
Because autolayout in Storyboard?
By the way ,how to move it smoothly?
Thank you guys.
UPDATE:
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.viewHolder setFrame:rectForAnimationAfter];
}
completion:^(BOOL finish){
}];
when I change code like this ,I can't move it down .
Here is my solution
unlock the autolayout!!!
First thing your animation block is nil. Here you should move your view down. At completion you are setting back you view without using any animation. For smoothness you need to move back your view animatedly.
I'm using the code
[UIView animateWithDuration:2.0
animations:^{
[self.slidingDownImage setFrame:CGRectMake(rect.origin.x,
rect.origin.y,
rect.size.width,
rect.size.height+100)];
}completion:^(BOOL finished){
if (finished) {
[self.slidingDownImage setFrame:CGRectMake(originalFrame.origin.x,
originalFrame.origin.y,
originalFrame.size.width,
originalFrame.size.height+100)];
}
}];
Its performed for swipe segue. But when I'm moving to the next controller, this animations are getting removed. I wish to save the view as it is (keeping animations) while transition to next view controller. Any ideas?
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!");
}];
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];
}];
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.