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.
Related
When a user makes a flick gesture on a UIScrollView, the UIScrollView gets a momentum and starts moving, then slow down and finally stop.
But how can I make this happen programmatically? I mean without a finger flicking, the UIScrollView just start moving automatically and then slow down to a speed of 0.
In my app I have made my UIScrollView unlike a normal UIScrollView (say it looks like a roller), so I want make a hint to the user that he can scroll it (and then everything get started!)
I have googled a lot but there seemed no way to solve my problem. The setContentOffset just couldn't make the natural "slow down and stop at somewhere ahead" effect.
Any idea would be appreciated.
Thanks in advance.
Try, something like this >
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:.8];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:(abs(1-3)*0.3)];
self.myScroll.contentOffset = CGPointMake(0, 500);
[UIView commitAnimations];
It is not currently what you need, but you can customise this code, and may be all be ok)
or use this code>
[UIView animateWithDuration:2.
delay:0.3
usingSpringWithDamping:1.
initialSpringVelocity:7.
options:UIViewAnimationOptionCurveEaseInOut animations:^{
//Animations
self.myScroll.contentOffset = CGPointMake(0, 500);
}
completion:^(BOOL finished) {
//Completion Block
}];
I think it is like you want(animation with damping like swipe effect)
I have a complex autolayout which needs to adapt to rotation by removing old constraints and adding new ones.
I have a grid layout of views inside a containerView.
The problem is when I call
[UIView animateWithDuration:0.4 animations:^{
[self.containerView layoutIfNeeded];
}];
The views always animate from the position [0,0] to their new position. What I would prefer is that the views would move from their old position (before I remove the constraints) to the new positions (after removal and addition of the new constraints)
Has someone been able to achieve this?
The following post gave me the hint to make it work:
But not the actual accepted answer but rather:
[UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionLayoutSubviews animations:^{
[self.view layoutIfNeeded];
} completion:nil];
The optional parameter options:UIViewAnimationOptionLayoutSubviews inspired me to try different options and the actual option needed was options:UIViewAnimationOptionBeginFromCurrentState
[UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionBeginFromCurrentState animations:^{
[self layoutIfNeeded];
} completion:nil];
Which allowed the animation to occur from the last position, even if constraints are removed and new ones are added.
I have UIScrollView which can zoom an UIView. One time I want to zoom out to the default state.
Here is my code.
[UIView animateWithDuration:0.3
animations:^{
[scroll zoomToRect:self.view.bounds animated:NO];
} completion:nil];
Wow. It jumps like hell. Seems like it sets zoomScale = 1 and then animating the frame.
I'll add a line.
[UIView animateWithDuration:0.3
delay:0 options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
[scroll zoomToRect:self.view.bounds animated:NO];
} completion:nil];
Works just fine. So how UIViewAnimationOptionBeginFromCurrentState helps in this case? From help I know
Start the animation from the current setting associated with an already in-flight animation.
But there is NO in-flight animations.
I found answer, it looks expedient but work fine.
write animation code in other place use method like 'performSelector:'
then it recognize correct current state
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
}]
I have been trying to build an entry effect for a logo to come from the top of the screen to the bottom and remain there when a new view loads in my application. I have seen all of the tutorials that use NSTimer to bounce an image but once my logo hits the bottom it needs to exit. I'm going to read up on animation block codes to see if my solution resides there.
Apologies I'm a new be and am very grateful for the assistance.
Set logo frame to top and then:
[UIView beginAnimations: #"moveLogo" context: nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
logoToMove.frame = CGRectMake( final frame at the bottom );
[UIView commitAnimations];
logoToMove is your logo, give it an outlet and hook it in xib.
So you will set the initial frame and in the animation - the final frame. The animation will do the rest of the job.
Change UIViewAnimationCurveLinear to a desired one if you don't like that. Also the duration to speed up or slow down the movement.
To remove the view at the end of your animation, the easiest way would be to use blocks :
logoToMove.frame = topRect;
[UIView animateWithDuration:duration
animations:^{
logoToMove.frame = bottomFrame;
}
completion:^(BOOL finished) {
[logoToMove removeFromSuperview];
}
];
Doing it like that gives you control over the animation and on what to do once it's finished in a single method