I want to add a blink animation in my app. For that purpose, I have used the code below.
if (buttonFlashing) return;
buttonFlashing = YES;
self.img_one.alpha = 1.0f;
[UIView animateWithDuration:0.12
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut |
UIViewAnimationOptionRepeat |
UIViewAnimationOptionAutoreverse |
UIViewAnimationOptionAllowUserInteraction
animations:^{
self.img_one.alpha = 0.0f;
}
completion:^(BOOL finished){
// Do nothing
}];
mode_count=1;
It works fine to hide & show the image view but I want to show another image when image is hidden then again show the previous image using above code. Above code just hides & shows the image view by using it's alpha. How can I do it?
Try this code,
[UIView transitionWithView:self.imageView
duration:1.2f
options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAutoreverse |UIViewAnimationOptionRepeat
animations:^{
self.imageView.image=[UIImage imageNamed:#"phone-icon.png"];
} completion:NULL];
Related
I'm trying to convert working UIView animations to using blocks. Aside from the completion callback, I don't see what's different about them. Could someone clarify something I might be missing?
This works as expected
[UIView beginAnimations:#"Curl" context:nil];
[UIView setAnimationDuration:.15];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.storyTextView cache:YES];
self.storyTextView.text = text;
[UIView commitAnimations];
This does change the page's text, but no animation is show, it's just an instant transition.
UIViewAnimationOptions curl = UIViewAnimationOptionTransitionCurlUp;
[UIView animateWithDuration:.15 delay:0 options:(UIViewAnimationOptionCurveEaseInOut | curl) animations:^{
self.storyTextView.text = text;
} completion:^(BOOL finished) {
if (finished){
// pass
}
}];
Moreover, setting delay in the blocks style animation does nothing to affect the instant transition, it just runs the completion block after the delay.
You'll want to try UIView's transitionWithView instead:
UIViewAnimationOptions curl = UIViewAnimationOptionTransitionCurlUp;
[UIView transitionWithView:self.view duration:0.15 options:(UIViewAnimationOptionCurveEaseInOut | curl) animations:^{
self.storyTextView.text = text;
} completion:nil];
Following is my code, Used for showing some fade effect while adding the table on a sub view. Problem is that code works for the first time. After adding table, when I hit close the Sub view button table is removed. But when I hit the Button to add table again on subview fade effect doesn't work fine
double delayInSeconds2 = 0.1;
dispatch_time_t popTime2 = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds2 * NSEC_PER_SEC));
dispatch_after(popTime2, dispatch_get_main_queue(), ^(void){
self.otlTableRightView.frame=CGRectMake(100, 68, 300, 378);
[self.otlTableRightView setAlpha:0.0];
[self.otlRightFromView addSubview:self.otlTableRightView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.2];
self.otlTableRightView.frame=CGRectMake(43, 68, 300, 378);
[UIView commitAnimations];
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[self.otlTableRightView setAlpha:0.0];
}completion:^(BOOL done){
}];
});
and I am using
[self.otlTableRightView removeFromSuperview];
to remove my table from my sub view
If you want repeat animation you shouldn't removeFromSuperview your subview! Then all the repeat method does not matter.
You also may consider simpler solution for that kind of behavior:
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.otlTableRightView setAlpha:0.0];
}
completion:^(BOOL done){
[self.otlTableRightView setAlpha:2.0];
}];
As you can see in option you can add multiple parameters.
To remove your table view with fade effect try this..Hope it wold work.
> [UIView animateWithDuration:1.0
> delay:0.0
> options: UIViewAnimationOptionCurveEaseInOut
> animations:^{
> [self.otlTableRightView setAlpha:0.0];
> }
> completion:^(BOOL done){
> [self.otlTableRightView removeFromSuperview];
> }];
After some search, Finally I found something that works in my case. Here, otlTableRightView is the outlet for my UItableView
self.otlTableRightView.alpha = 0;
[UIView beginAnimations:#"fade in" context:nil];
[UIView setAnimationDuration:2.0];
self.otlTableRightView.alpha = 1.0;
[UIView commitAnimations];
I have this code to simulate a multiple camera flash
[UIView animateWithDuration:0.1
delay:0.f
options:UIViewAnimationOptionAutoreverse
animations:^{
[UIView setAnimationRepeatCount:2];
flash.alpha=1.f;
}
completion:^(BOOL finished) {
flash.alpha = 0;
}];
flash is a white UIImageView (full screen) that starts with alpha = 0.
If you try to use this code, you will notice that at the end flash remains full white for a little time and it's not perfect for my effects, what can I do to solve this?
The problem with your code is you do autoreverse using the option UIViewAnimationOptionAutoreverse, while also specifying your own final state in the completion block.
Try this:
[UIView animateWithDuration:0.1f
delay:0
options:UIViewAnimationOptionAutoreverse
animations:^{
[UIView setAnimationRepeatCount:2];
flash.alpha=1.f;
}
completion:nil];
I've got a UILabel that slides in and out of view, but after it slides back in it disappears. I want it to persist.
How can I achieve this? Also, why does this happen?
Here's the code:
[UIView animateWithDuration:0.1
delay:0.0
options:UIViewAnimationOptionAutoreverse
animations:^{
[self.listLabel setFrame:CGRectMake(325, 141, 320, 181)];
}
completion:nil];
Thanks.
In official documentation
UIViewAnimationOptionAutoreverse
Run the animation backwards and forwards. Must be combined with the UIViewAnimationOptionRepeat option.
Why don't you use UIViewAnimationOptionCurveEaseOut and UIViewAnimationOptionCurveEaseIn animation option for your label?
Just set your label's frame.origin.x = [outside the right side of it's superview's bound]
and set it back to it's original position when you want to slide-In again using EasyOut animation.
Here's something what I'm talking about...
CFRect frame = self.listLabel.frame;
//Point to hide your label by sliding it outside the right side of it's parent's view.
// mask or clipToBounds of parent's view must be YES
frame.origin.x = [self.listLabel.superview.frame.size.width];
[UIView animateWithDuration:0.1
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
[self.listLabel setFrame:frame];
}
completion:nil];
And When you want to slide back in, use opposite animation and label's original position, of course you need to store it's original position somewhere so you could slide-in it back.
[UIView animateWithDuration:0.1
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[self.listLabel setFrame:label_original_frame];
}
completion:nil];
UIViewAnimationOptionAutoreverse is designed for a cyclical animation. To just bounce something offscreen and back, you should just write it as 2 animations:
CGRect originalFrame = self.listLabel.frame;
[UIView animateWithDuration:0.05
delay:0.0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
[self.listLabel setFrame:CGRectMake(325, 141, 320, 181)];
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.05
delay:0.0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
[self.listLabel setFrame:originalFrame];
}
completion:nil];
}
];
As there still seems to be no valid answer, I propose a (now possible) approach:
In Xcode 6, with the app running in the simulator, go to "Debug" in the top bar, select "View Debugging" and "Capture View Hierarchy". Then go and search your missing Label. You can also see properties etc. of the Label in the right Xcode bar.
I'm trying to do a cross dissolve on three UILabels (display1, display2, display3), by using a block animation to fade out, change text and then fade them in one at a time. The code I'm using is:
[UIView animateWithDuration:1.0 delay: 1.0
animations:^{
display1.alpha = 0.0;
display2.alpha = 0.0;
display3.alpha = 0.0;
}
completion:^{
[display1 setText:[NSString stringWithFormat:#"%#",[engine getstring]]];
[display2 setText:[NSString stringWithFormat:#"%#",[engine getstring]]];
[display3 setText:[NSString stringWithFormat:#"%#",[engine getstring]]];
[UIView animateWithDuration:1.0 delay:1.0
animations:^{
display1.alpha = 1.0;
[UIView animateWithDuration:1.0 delay:1.0
animations:^{
display2.alpha = 1.0;
[UIView animateWithDuration:1.0
delay:1.0
animations:^{
display3.alpha = 1.0;
} completion:nil];
} completion:nil];
} completion:nil];
}];
I get the following warnings:
Method '+animateWithDuration:delay:animations:completion:' not found*
and
'UIView' may not respond to method '+animateWithDuration:delay:animations:completion:'
I'm using Xcode 4.0 with an iOS Build Target of 4.3.
You want to use
+ animateWithDuration:delay:options:animations:completion:
instead. Note the options: in the middle.