I tried to find a solution for it for a while now.
I have a XIB called CameraViewController.xib. I have a few animations in it. (Alpha, Scale, Transition) I use AutoLayout and Interface Builder, xCode 6 and Objective C. (iPhone)
Every animation worked fine until 2 weeks ago they just stopped working. I can´t figure out why. Every animation is ignored and jumps directly to endstate.
It´s just in this XIB in all other XIBs and my Storyboards ViewControllers every animation is working fine.
There is no Error. I tried all possible forms of animating down to CoreAnimations but they all jump to endstate.
The XIB is complex and it has a lot of code in it. I don´t want to build the XIB again trying and trying until I find the mistake.
Anybody got the same problem or an idea ? Or a link for me where I can find out why animations aborting and jumping ?
This is driving me crazy...
EDIT :
[UIView animateWithDuration:0.5f
animations:^{
liveLabel.alpha = 0.7;
liveRedDot.alpha = 1.0;
}
completion:^(BOOL finished){
nil;
}];
CABasicAnimation *morph = [CABasicAnimation animationWithKeyPath:#"cornerRadius"];
morph.fromValue = #0;
morph.toValue = #37.5;
morph.duration = 0.5;
[playStopButton.layer addAnimation:morph forKey:#"morph"];
I also tried different code snippets for the same animation but not a single one is working. As I said same code is working in other XIBs or ViewControllers of my StoryBoard :
[UIView animateWithDuration:0.5 animations:^{
playStopButton.transform = CGAffineTransformMakeScale(0.6,0.6);
playStopButton.backgroundColor = UIColorFromRGBWithAlpha(0x000000,0.3);
}];
[UIView beginAnimations:#"button" context:nil];
[UIView setAnimationDuration:0.5];
playStopButton.transform = CGAffineTransformMakeScale(0.6,0.6);
playStopButton.backgroundColor = UIColorFromRGBWithAlpha(0x000000,0.3);
[UIView commitAnimations];
[UIView
animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
playStopButton.transform = CGAffineTransformMakeScale(0.6, 0.6);
}
completion:nil];
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 created some animations in my project. Basically, I use UIView animate and CGAffineTransform, but a very strange thing happened and I have no idea. Hope someone can help me solve this problem. Thanks in advance.
This is the strange thing:
After the user clicks on a button, the button slides off screen and another two buttons slide on the screen (I just changed the center point of these buttons to achieve this animation). And, some time later, a view on the screen start shaking (I use CGAffineTransform to achieve this).
At this moment, the strange thing happens - the button that previous slid off screen show up at its original position again and the other two buttons disappear (No animation, just shows up and disappear).
The following is the related code,
1) Button slide off and slide in animation related code
- (IBAction)start:(id)sender
{
// 1. Slide in cancel and pause button
[UIView animateWithDuration:0.5f animations:^{
[startButton setCenter:CGPointMake(startButton.center.x + 300.0f, startButton.center.y)];
[cancelButton setCenter:CGPointMake(cancelButton.center.x + 300.0f, cancelButton.center.y)];
[pauseButton setCenter:CGPointMake(pauseButton.center.x + 300.0f, pauseButton.center.y)];
} completion:^(BOOL finished) {
if (finished) {
NSLog(#"Move finished");
}
}];
}
2) The view shaking animation related code
- (void)shakeView:(UIView *)viewToShake
{
CGFloat t = 2.0;
CGAffineTransform translateRight = CGAffineTransformTranslate(CGAffineTransformIdentity, t, 0.0);
CGAffineTransform translateLeft = CGAffineTransformTranslate(CGAffineTransformIdentity, -t, 0.0);
viewToShake.transform = translateLeft;
[UIView animateWithDuration:0.07 delay:0.0 options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat animations:^{
[UIView setAnimationRepeatCount:2.0];
viewToShake.transform = translateRight;
} completion:^(BOOL finished) {
if (finished) {
[UIView animateWithDuration:0.05 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
viewToShake.transform = CGAffineTransformIdentity;
} completion:nil];
}
}];
}
This isn't weird, it's a common problem with
auto layout. If you move UI elements by changing frames, then as soon as something else takes place that requires laying out views, the moved views will revert to the position defined by their constraints. To fix it, you either need to turn off auto layout, or do your animations by changing constraints not frames.
I have tried your code in my test project. The problem is probably because you are using Autolayout in your xib.
Please checking your xib file and uncheck the Autolayout property.
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
Having a puzzling problem. I have a universal app with a lot of shared code between the iPad and iPhone versions. There are different layouts in the nibs but essentially the same views and view hierarchy - one UIView used as a container for two sibling UITextViews.
UIView mainView with children:
UITextView passageTextView
UITextView notesTextView
One UITextView is hidden, the other visible.
The following is my code. The section commented out was my original animation attempt. This worked just as desired on the iPad, but not on the iPhone. The uncommented section is take 2, using the method recommended in the docs. The uncommented code does not work on either the iPad or iPhone - it hides/unhides my views but without any animation. If I add code to the completion block that also gets executed, so it's doing something, just not animating.
/*
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mainView cache:YES];
passageTextView.hidden = YES;
notesTextView.hidden = NO;
[UIView commitAnimations];
*/
UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationTransitionFlipFromRight;
[UIView transitionWithView:mainView
duration:1.0
options:options
animations:^{ passageTextView.hidden = YES; notesTextView.hidden = NO; }
completion:NULL];
Edit: Still working on the problem, hoping someone has a suggestion.
Additional update
Figured out why the following was not working in the iPhone:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mainView cache:YES];
passageTextView.hidden = YES;
notesTextView.hidden = NO;
[UIView commitAnimations];
I had neglected to wire the view to mainView in Interface Builder. Hours debugging and I just now thought to check that.
But, I still do not know why animation blocks are not working for either the iPhone or iPad. I have tried several approaches but I'm not getting any animation even though the show/hides are working.
I think you are using the wrong animation option.
Replace your second animation option by UIViewAnimationOptionTransitionFlipFromLeft (note the Option between Animation and Transition)
I believe that UIViewAnimationTransitionFlipFromLeft (which is what you have in your code) is a UIViewAnimationTransition not a UIViewAnimationOptions.
I'm trying to add a continuous animation onto my UITableViewCell-Subclass.
It's a rather easy one with an Image fading in and out (fading between 0.4 alpha and 1.0),
what I've tried so far ist the following:
-(void)animateRecordingIndicator{
[UIView beginAnimations:#"RecordingIndicatorAnimation" context:nil];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationFinished)];
if (animatedImageView.alpha == 0.4)
animatedImageView.alpha = 1.0;
else
animatedImageView.alpha = 0.4;
[UIView commitAnimations];
}
the code within animationFinished is as follows:
-(void)animationFinished{
if (doShowAnimation) {
[self performSelectorOnMainThread:#selector(animateRecordingIndicator) withObject:nil waitUntilDone:YES];
}
}
what I expect should be clear by now, but what I get is simply a crash with Xcode loading Stackframes more or less eternally :)
According to the UIView class reference, you are now discouraged from using the commitAnimations method. Instead use the following:
animateWithDuration:delay:options:animations:completion:
I imagine the infinite recursion you are encountering is related to Apple's reasons for making that recommendation.