UIView animations are getting removed when next controller is pushed - ios

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?

Related

dismissviewcontrolleranimated not smooth

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.

Move UIView with animation and it rolls back by itself

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.

Animated UIView hangs on screen after pressing back

I can't figure out what's happening here. I have two views on screen that serve as a "gate" until the camera is ready to record. Afterwards they slide out. It works, i'm happy, and that's great. The problem is regardless of when I choose to go "back" on the navigation controllers back option (be that during the animation or after it finishes) the left view "sticks out" on the view controller i'm going back to.
I've tried removing all animations -and- removing the views from the superview when the ViewWillDisappear method... but no luck, this view persistently sticks out on the home page when I click back from the recording page.
-(void)animateViewsOut
{
[UIView animateKeyframesWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionCurveEaseIn animations:^{
_leftView.layer.transform = CATransform3DMakeTranslation(-_leftView.frame.size.width, 0.0, 0.0);
_rightView.layer.transform = CATransform3DMakeTranslation(_rightView.frame.size.width, 0.0, 0.0);
} completion:^(BOOL finished) {
[_leftView removeFromSuperview];
[_rightView removeFromSuperview];
}];
}
and my attempt to solve the problem
- (void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[_leftView.layer removeAllAnimations];
[_rightView.layer removeAllAnimations];
[_leftView removeFromSuperview];
[_rightView removeFromSuperview];
[[CameraEngine engine] shutdown];
}
So, as it turns out the problem's root was due to me inserting the views on the view controllers main view
[self.view addsubview:_leftView];
[self.view addsubview:_rightView];
I instead created a container for the views that I built onto the storyboard, then added the the views as subviews of that overview, and kept the same animation, except on completion instead of removing the views individually, I just remove the overlay container instead (change in the code below).
-(void)animateViewsOut
{
[UIView animateKeyframesWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionCurveEaseIn animations:^{
_leftView.layer.transform = CATransform3DMakeTranslation(-_leftView.frame.size.width, 0.0, 0.0);
_rightView.layer.transform = CATransform3DMakeTranslation(_rightView.frame.size.width, 0.0, 0.0);
} completion:^(BOOL finished) {
[_overlayView removeFromSuperview];
}];
}
After I made this change, the views didn't persist when tapping back in the navigation controller.
I removed all of the code from the viewWillDisappear method, removing the overlay container after the animation completed solved the problem on its own.
- (void) viewWillDisappear:(BOOL)animated {}

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];
}];

Push a detail view in UITableViewCell class

My class inherit from UITableViewCell, i have make some custom transitions to push a new detail view when an image get selected.
[UIView transitionWithView:self.masterView duration:0.5 options:UIViewAnimationOptionShowHideTransitionViews
animations:^ {
[self.masterView addSubview:self.detailImage];
}
completion:nil];
My code works fine, the detailImage subview is shown with a transition, but this transition is not what i want exactly. What i want to perform is a simple transition from bottom to up. The list of UIViewAnimation doesn't contain such animation.
Is there any way to use that transition without changing my class inheritance to UINavigationController ?
If I understand you right, the code below may be what you want.
CGRect detailImageFrameOri = self.detailImage.frame;
CGRect detailImageFrame = detailImageFrameOri;
detailImageFrame.origin.y += self.detailImage.frame.size.height;
self.detailImage.frame = detailImageFrame;
[self.masterView addSubview:self.detailImage];
[UIView animateWithDuration:0.5 animations:^{
self.detailImage.frame = detailImageFrameOri;
}];
Hope this can help you.
Edit:
from top to bottom,
CGRect detailImageFrame = self.detailImage.frame;
detailImageFrame.origin.y += self.detailImage.frame.size.height;
[self.masterView addSubview:self.detailImage];
[UIView animateWithDuration:0.5
animations:^{
self.detailImage.frame = detailImageFrame;
}
completion:^(BOOL finished) {
[self.detailImage removeFromSuperview];
}];

Resources