I am trying to set a delay for my animation, so once it appears and then disappears, I want to wait a certain amount of seconds for it to reappear. I have tried placing it in multiple spots throughout my code, but it was all the same result.
- (void) startRedDot {
redDotTimer = [NSTimer scheduledTimerWithTimeInterval:1.5
target:self
selector:#selector(moveButtonWithAnimation)
userInfo:nil
repeats:YES];
[redDotTimer fire];
}
-(void) moveButtonRandomly {
CGSize limits;
CGPoint newPosition;
// Get limits
limits.width = gameView.frame.size.width - redButton.frame.size.width;
limits.height = gameView.frame.size.height - redButton.frame.size.height;
// Calculate new Position
newPosition = (CGPoint){ limits.width * drand48(), limits.height * drand48() };
// Set new frame
redButton.frame = (CGRect){ newPosition, redButton.frame.size };
}
- (void) moveButtonWithAnimation {
CGFloat fadeDurration;
if ( !redButton )
return; // only invoke the button if it exists
fadeDurration = 0.0f;
//Fade Out
[UIView animateWithDuration: fadeDurration animations:^{
redButton.alpha = 0.0f;
} completion:^(BOOL finished) {
// Move the button while it is not visible
[self moveButtonRandomly];
[UIView setAnimationDelay:9.0];
// Fade in
[UIView animateWithDuration: fadeDurration animations:^{
redButton.alpha = 4.0f;
}];
}];
}
setAnimationDelay should use in beginAnimation and commitAnimation block, and it was old way to do animation in iOS. In your case try this:
- (void) moveButtonWithAnimation {
CGFloat fadeDurration;
if ( !redButton )
return; // only invoke the button if it exists
fadeDurration = 2.0f;
//Fade Out
[UIView animateWithDuration: fadeDurration animations:^{
redButton.alpha = 0.0f;
} completion:^(BOOL finished) {
// Move the button while it is not visible
[self moveButtonRandomly];
[UIView animateWithDuration:fadeDurration delay:2.0 options:0 animations:^{
redButton.alpha = 1.0f;
} completion:nil];
}];
}
Related
I would like to include in my application a compass and labels cardinal gravitationally rotate and maintain its position as the compass of iOS application.
I've done some code and separately running, but when they work together goes crazy.
This is part of the code I use:
UIImageView * imgCompass;
UIImageView * north;
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.headingFilter = 1;
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];
[locationManager startUpdatingHeading];
motionManager = [[CMMotionManager alloc] init];
motionManager.accelerometerUpdateInterval = 0.01;
motionManager.gyroUpdateInterval = 0.01;
[motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
if (!error) {
[self outputAccelertionData:accelerometerData.acceleration];
}
else{
NSLog(#"%#", error);
}
}];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
// Convert Degree to Radian and move the needle
newRad = -newHeading.trueHeading * M_PI / 180.0f;
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.viewCompass.transform = CGAffineTransformMakeRotation(newRad);
} completion:nil];
}
- (void)outputAccelertionData:(CMAcceleration)acceleration{
//UIInterfaceOrientation orientationNew;
// Get the current device angle
float xx = -acceleration.x;
float yy = acceleration.y;
float angle = atan2(yy, xx);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
// Add 1.5 to the angle to keep the image constantly horizontal to the viewer.
[self.north setTransform:CGAffineTransformMakeRotation(angle - 1.5)];
} completion:nil];
}
Any ideas? Thank You. I'm desperate...
I solved. Simply subtract the radius of the compass and add the result to the object you want. in my case north, east, west and south are UIImageView.
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
self.lblGrados.text = [NSString stringWithFormat:#"%.0f°", newHeading.magneticHeading];
// Convert Degree to Radian and move the needle
newRad = -newHeading.trueHeading * M_PI / 180.0f;
[UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
compassView.transform = CGAffineTransformMakeRotation(newRad);
} completion:nil];
[UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
[self.north setTransform:CGAffineTransformMakeRotation(-newRad)];
[self.south setTransform:CGAffineTransformMakeRotation(-newRad)];
[self.east setTransform:CGAffineTransformMakeRotation(-newRad)];
[self.west setTransform:CGAffineTransformMakeRotation(-newRad)];
} completion:nil];
}
I have a view controller called ViewController in which I have two methods, hideAd and showAd:
// Method is called when the iAd is loaded.
-(void)showAd:(ADBannerView *)banner {
// Creates animation.
[UIView beginAnimations:nil context:nil];
// Sets the duration of the animation to 1.
[UIView setAnimationDuration:1];
// Sets the alpha to 1.
// We do this because we are going to have it set to 0 to start and setting it to 1 will cause the iAd to fade into view.
[banner setAlpha:1];
// Performs animation.
[UIView commitAnimations];
}
// Method is called when the iAd fails to load.
-(void)hideAd:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
// Creates animation.
[UIView beginAnimations:nil context:nil];
// Sets the duration of the animation to 1.
[UIView setAnimationDuration:1];
// Sets the alpha to 0.
// We do this because we are going to have it set to 1 to start and setting it to 0 will cause the iAd to fade out of view.
[banner setAlpha:0];
// Performs animation.
[UIView commitAnimations];
}
I would like to be able to call these methods from my skscenes, two of which called startview and gameview. I tried implemeting this solution: How to show iAd on a certain SKScene and hide it on the other one, but setDelegate does not work for me. In what way can I hide and show my banner iads?
Instead of chaining alpha, move its position.
-(void)showBannerView
{
if (_adBannerViewIsVisible)
{
return;
}
if (_adBannerView)
{
_adBannerViewIsVisible = true;
CGRect frame = _adBannerView.frame;
if(app_dsp.isBannerOnTop)
{
frame.origin.x = 0.0f;
frame.origin.y = -_adBannerView.frame.size.height;
}
else
{
frame.origin.x = 0.0f;
frame.origin.y = self.size.height;// - _adBannerView.frame.size.height;
}
_adBannerView.frame = frame;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
if(app_dsp.isBannerOnTop)
{
frame.origin.x = 0.0f;
frame.origin.y = 0.0f;
}
else
{
frame.origin.x = 0.0f;
frame.origin.y = self.size.height - _adBannerView.frame.size.height;
}
_adBannerView.frame = frame;
[UIView commitAnimations];
}
}
-(void)hideBannerView
{
if (!_adBannerViewIsVisible)
{
return;
}
if (_adBannerView)
{
_adBannerViewIsVisible = false;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
CGRect frame = _adBannerView.frame;
if(app_dsp.isBannerOnTop)
{
frame.origin.x = 0.0f;
frame.origin.y = -_adBannerView.frame.size.height ;
}
else
{
frame.origin.x = 0.0f;
frame.origin.y = self.size.height ;
}
_adBannerView.frame = frame;
[UIView commitAnimations];
}
}
I have some problems with animations. Here is what I am trying to do.
First I have a for loop where I make some animations of UILabels, for example
label1.frame = CGRectMake(xBoard, 5, textWidth, term1Label.frame.size.height);
xBoard = xBoard + textWidth;
label1.textColor = term1Label.textColor;
label1.font = [UIFont italicSystemFontOfSize:textHeight];
label1.textAlignment = term1Label.textAlignment;
label1.text = label1String;
label1.alpha = 0;
label1.backgroundColor = [UIColor clearColor];
[boardView addSubview:label1];
[UIView animateWithDuration:2.0*time
delay:timeDelay
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
label1.alpha = 1;
} completion:^(BOOL finished){
}
];
timeDelay = timeDelay + 2.0*time;
Some labels appear, some disappear, some change color. Everything is working fine until I make second loop. Then the first part of code just appear (the animations of changing color are still working but all labels from first loop are visible and do not animate. Second loop animates fine.
I was trying to replace the animations [UIView animateWithDuration:...] with CABasicAnimations and save them in one NSMutableArray with queue, but I am not successful. Probably my knowledge is too short yet. Any help is welcome. Thanks!!!
I am in the middle of solving my problem. Doing my loops I am saving animation parameters in the table
NSArray *animation1 = [[NSArray alloc]initWithObjects:[NSNumber numberWithInt:label1.tag], [NSNumber numberWithInt:3],[NSNumber numberWithFloat:0.5f*time],[NSNumber numberWithFloat:timeDelay],[NSNumber numberWithFloat:0],nil];
[animations addObject:animation1];
in the end of void I call [self performAnimations];
- (void)performAnimations {
if ([[self animations] count] == 0) return;
for (int i=0; i<[[self animations] count]; i++) {
int tag = [[[animations objectAtIndex:i]objectAtIndex:0]intValue];
int animation = [[[animations objectAtIndex:i]objectAtIndex:1]intValue];
float animTime = [[[animations objectAtIndex:i]objectAtIndex:2]floatValue];
float animDelay = [[[animations objectAtIndex:i]objectAtIndex:3]floatValue];
float parameter = [[[animations objectAtIndex:i]objectAtIndex:4]floatValue];
UILabel *label = [UILabel alloc];
UIView *view = [UIView alloc];
if ([[self.view viewWithTag:tag] isKindOfClass:[UILabel class]]){
label = (UILabel *)[self.view viewWithTag:tag];
} else if ([[self.view viewWithTag:tag] isKindOfClass:[UIView class]]) {
view = (UIView *)[self.view viewWithTag:tag];
}
switch (animation) {
case 1:
[PolyCalcsViewController colorizeLabelForAWhile:label withUIColor:[UIColor yellowColor] animated:YES withTime:animTime withDelay:animDelay];
break;
case 2:
[PolyCalcsViewController appear:label withTime:animTime withDelay:animDelay];
break;
case 3:
[PolyCalcsViewController disappear:label withTime:animTime withDelay:animDelay];
break;
case 4:
[PolyCalcsViewController moveView:view withOffset:parameter withTime:animTime withDelay:animDelay];
break;
default:
break;
}
}
[animations removeAllObjects];
}
+(void)colorizeLabelForAWhile:(UILabel *)label withUIColor:(UIColor *)tempColor animated:(BOOL)animated withTime:(float)time withDelay:(float)delay{
UILabel *tempLabel = [[UILabel alloc] init];
tempLabel.textColor = tempColor;
tempLabel.font = label.font;
tempLabel.alpha = 0;
tempLabel.textAlignment = label.textAlignment;
tempLabel.text = label.text;
tempLabel.backgroundColor = [UIColor clearColor];
[label.superview addSubview:tempLabel];
tempLabel.frame = label.frame;
if (animated) {
[UIView animateWithDuration:time
delay:delay
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
// Animate it
label.alpha = 0;
tempLabel.alpha = 1;
} completion:^(BOOL finished){
[UIView animateWithDuration:time
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
// Animate it back.
label.alpha = 1;
tempLabel.alpha = 0;
} completion:^(BOOL finished){
// Remove the tempLabel view when we are done.
[tempLabel removeFromSuperview];
}];
}];
} else {
// Change it back at once and remove the tempLabel view.
label.alpha = 1.0;
[tempLabel removeFromSuperview];
}
}
+(void)appear:(UILabel *)label withTime:(float)time withDelay:(float)delay{
[UIView animateWithDuration:time
delay:delay
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
label.alpha = 1.0;
} completion:^(BOOL finished){
NSLog(#"Anim Appear %d",label.tag);
}];
}
+(void)disappear:(UILabel *)label withTime:(float)time withDelay:(float)delay{
[UIView animateWithDuration:time
delay:delay
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
label.alpha = 0.0;
} completion:^(BOOL finished){
NSLog(#"Anim Disappear %d",label.tag);
[label removeFromSuperview];
}];
}
The point is that program is not performing animations in sequence how it is in the table animations. I think I should give up of time delay and run the next animation when the previous one is finished. I could make a counter in the completion:(BOOL finished) block, but I do not know how because the function doesn't accept external variable. Any ideas how to detect the end of animation and control the table execution? Thanks.
Finally I have solved the problem. Here is a correctly working code
- (void)performAnimations {
// Finish when there are no more animations to run
int i = animationNumber;
int tag = [[[animations objectAtIndex:i]objectAtIndex:0]intValue];
int animation = [[[animations objectAtIndex:i]objectAtIndex:1]intValue];
float animTime = [[[animations objectAtIndex:i]objectAtIndex:2]floatValue];
//float animDelay = [[[animations objectAtIndex:i]objectAtIndex:3]floatValue];
float animDelay = 0;
float parameter = [[[animations objectAtIndex:i]objectAtIndex:4]floatValue];
UILabel *label = [UILabel alloc];
UIView *view = [UIView alloc];
if ([[self.view viewWithTag:tag] isKindOfClass:[UILabel class]]){
label = (UILabel *)[self.view viewWithTag:tag];
} else if ([[self.view viewWithTag:tag] isKindOfClass:[UIView class]]) {
view = (UIView *)[self.view viewWithTag:tag];
}
switch (animation) {
case 1:
[self colorizeLabelForAWhile:label withUIColor:[UIColor yellowColor] animated:YES withTime:animTime withDelay:animDelay];
break;
case 2:
[self appear:label withTime:animTime withDelay:animDelay];
break;
case 3:
[self disappear:label withTime:animTime withDelay:animDelay];
break;
case 4:
[self moveView:view withOffset:parameter withTime:animTime withDelay:animDelay];
break;
default:
break;
}
}
-(void)animationDidFinished{
animationNumber = animationNumber + 1;
if (animationNumber == [[self animations] count]) {
[animations removeAllObjects];
return;
} else {
[self performAnimations];
}
}
-(void)colorizeLabelForAWhile:(UILabel *)label withUIColor:(UIColor *)tempColor animated:(BOOL)animated withTime:(float)time withDelay:(float)delay{
UILabel *tempLabel = [[UILabel alloc] init];
tempLabel.textColor = tempColor;
tempLabel.font = label.font;
tempLabel.alpha = 0;
tempLabel.textAlignment = label.textAlignment;
tempLabel.text = label.text;
tempLabel.backgroundColor = [UIColor clearColor];
[label.superview addSubview:tempLabel];
tempLabel.frame = label.frame;
if (animated) {
[UIView animateWithDuration:time
delay:delay
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
// Animate it
label.alpha = 0;
tempLabel.alpha = 1;
} completion:^(BOOL finished){
[UIView animateWithDuration:time
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
// Animate it back.
label.alpha = 1;
tempLabel.alpha = 0;
} completion:^(BOOL finished){
// Remove the tempLabel view when we are done.
[tempLabel removeFromSuperview];
if (finished) {
[self animationDidFinished];
}
}];
}];
} else {
// Change it back at once and remove the tempLabel view.
label.alpha = 1.0;
[tempLabel removeFromSuperview];
}
}
-(void)appear:(UILabel *)label withTime:(float)time withDelay:(float)delay{
[UIView animateWithDuration:time
delay:delay
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
label.alpha = 1.0;
} completion:^(BOOL finished){
NSLog(#"Anim Appear %d",label.tag);
if (finished) {
[self animationDidFinished];
}
}];
}
-(void)disappear:(UILabel *)label withTime:(float)time withDelay:(float)delay{
[UIView animateWithDuration:time
delay:delay
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
label.alpha = 0.0;
} completion:^(BOOL finished){
NSLog(#"Anim Disappear %d",label.tag);
[label removeFromSuperview];
if (finished) {
[self animationDidFinished];
}
}];
}
-(void)moveView:(UIView *)view withOffset:(float)offset withTime:(float)time withDelay:(float)delay{
[UIView animateWithDuration:time
delay:delay
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
CGRect frame = view.frame;
frame.origin.y += offset;
view.frame = frame;
} completion:^(BOOL finished){
if (finished) {
[self animationDidFinished];
}
}
];
}
I've looked at several posts, including [this one].1 This is exactly what I want to do, but I cannot get it to work.
I want to show the user that they have pressed a record button, and that they will need to press it again to stop recording.
So far, the code for the start recording method looks like this:
NSLog(#"DetailVC - recordAudio - soundFilePath is %#", soundFile);
[audioRecorder prepareToRecord];
recording = YES;
NSLog(#"start recording");
NSLog(#"1");
//[autoCog startAnimating];
[audioRecorder recordForDuration:120];
recording = NO;
//Start a timer to animate the record images
if (recording == YES) {
toggle = FALSE;
timer = [NSTimer scheduledTimerWithTimeInterval: 2.0
target: self
selector: #selector(toggleButtonImage:)
userInfo: nil
repeats: YES];
//UIImage *changeImage = [UIImage imageNamed:stopButtonFile];
//[recordButton setImage:changeImage forState:UIControlStateNormal];
//[timer invalidate];
//timer = nil;
NSLog(#"2");
}
and the toggleButton method looks like this:
- (void)toggleButtonImage:(NSTimer*)timer
{
NSLog(#"%s", __FUNCTION__);
if(toggle)
{
NSLog(#"1");
/*
[UIView beginAnimations];
recordButton.opacity = 0.0;
[recordButton setAnimationDuration: 1.5];
[recordButton commitAnimations];
[recordButton setImage:[UIImage imageNamed:#"record.png"] forState: UIControlStateNormal];
*/
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; //delete "EaseOut", then push ESC to check out other animation styles
[UIView setAnimationDuration: 0.5];//how long the animation will take
[UIView setAnimationDelegate: self];
recordButton.alpha = 1.0; //1.0 to make it visible or 0.0 to make it invisible
[UIView commitAnimations];
}
else
{
NSLog(#"2");
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; //delete "EaseOut", then push ESC to check out other animation styles
[UIView setAnimationDuration: 0.5];//how long the animation will take
[UIView setAnimationDelegate: self];
recordButton.alpha = 0.0; //1.0 to make it visible or 0.0 to make it invisible
[UIView commitAnimations];
//[recordButton setImage:[UIImage imageNamed:#"stopGrey.png"] forState: UIControlStateNormal];
}
toggle = !toggle;
}
I get to see the logs showing that the loop is iterating, but:
the images do not switch, and
the operation is not running in parallel with the record method.
I would appreciate any ideas as to how to proceed.
Expanding on Ashley's answer, I'd go with something more like this:
- (IBAction)record:(id)sender {
self.recording = !self.recording;
if (!self.recording) {
[UIView animateWithDuration:0.1
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.recordButton.alpha = 1.0f;
}
completion:^(BOOL finished){
}];
} else {
self.recordButton.alpha = 1.0f;
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction
animations:^{
self.recordButton.alpha = 0.0f;
}
completion:^(BOOL finished){
}];
}
}
Try this:
- (IBAction)record:(id)sender
{
self.recording = !self.recording;
[self toggleButton];
}
- (void) toggleButton
{
if (!self.recording) {
self.recordButton.alpha = 1.0;
return;
}
[UIView animateWithDuration: 0.5
delay: 0.0
options: UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
self.recordButton.alpha = !self.recordButton.alpha;
}
completion:^(BOOL finished) {
[self toggleButton];
}];
}
I'm trying to slide a UIImageView into a UIView, and fade it in at the same time. And then I want it to fade and slide out.
The code below should do this, but it doesn't.
Instead, the leftArrow view is at full alpha when it slides in. So the first animation is skipping the alpha fade-in. Then the second animation just fades it out, it does not move the leftArrow view. I've tried lots of variations (using bounds instead of frames, doing the animation in a class method (as opposed to an instance method), and I cannot determine why the view seems to arbitrarily pick one thing to do rather than the other, or both.
Maybe I just need fresh eyes.
TIA,
Mike
- (void) flashHorizontalArrowsForView: (UIView *)view {
DebugLog(#" flashHorizontalArrows");
float duration = 1.5f;
// create the views
UIImageView *leftArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"leftCouponDetailArrow.png"]];
leftArrow.frame = CGRectMake(0 -leftArrow.image.size.width,
HORIZONTAL_ARROW_START_Y,
leftArrow.image.size.width,
leftArrow.image.size.height);
[view addSubview:leftArrow];
leftArrow.alpha = 0.0f;
// animate them in...
[UIView beginAnimations:#"foo" context:leftArrow];
[UIView setAnimationDelay: 0.0f ]; // in seconds
[UIView setAnimationDuration: duration ];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDidStopSelector:#selector(animationReallyDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
leftArrow.alpha = 1.0f;
CGRect LFrame = leftArrow.frame;
LFrame.origin.x += LFrame.size.width; // move it in from the left.
leftArrow.frame = LFrame;
[UIView commitAnimations];
// and animate them out
// delay enough for the first one to finish
[UIView beginAnimations:#"bar" context:leftArrow];
[UIView setAnimationDelay: duration+0.05 ]; // in seconds
[UIView setAnimationDuration: duration ];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDidStopSelector:#selector(animationReallyDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
leftArrow.alpha = 0.0f;
CGRect LLFrame = leftArrow.bounds;
LLFrame.origin.x -= LLFrame.size.width; // move it off to the left.
leftArrow.bounds = LLFrame;
[UIView commitAnimations];
}
Solution is simple - when the first animation finishes, have it call another method, like horizontal2, and in horizontal2, do the animate_them_out part.
- (void) flashHorizontalArrowsForView: (UIView *)view{
DebugLog(#" flashHorizontalArrows");
self.theView = view;
float duration = 1.5f;
// create the views
UIImageView *left = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"leftCouponDetailArrow.png"]];
self.leftArrow = left;
[left release];
leftArrow.tag = LEFT_ARROW_TAG;
leftArrow.frame = CGRectMake(0 -leftArrow.image.size.width,
HORIZONTAL_ARROW_START_Y,
leftArrow.image.size.width,
leftArrow.image.size.height);
[theView addSubview:leftArrow];
leftArrow.alpha = 0.0f;
UIImageView *right = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"rightCouponDetailArrow.png"]];
self.rightArrow = right;
[right release];
rightArrow.tag = RIGHT_ARROW_TAG;
rightArrow.frame = CGRectMake(view.frame.size.width, // -leftArrow.image.size.width,
HORIZONTAL_ARROW_START_Y,
leftArrow.image.size.width,
leftArrow.image.size.height);
[theView addSubview:rightArrow];
rightArrow.alpha = 0.0f;
// --------------------------------------------
// animate them in...
[UIView beginAnimations:#"foo" context:nil];
[UIView setAnimationDelay: 0.0f ]; // in seconds
[UIView setAnimationDuration: duration ];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDidStopSelector:#selector(horizontalPart2)];
[UIView setAnimationDelegate:self];
leftArrow.alpha = 1.0f;
rightArrow.alpha = 1.0f;
CGRect LFrame = leftArrow.frame;
LFrame.origin.x += LFrame.size.width; // move it in from the left.
leftArrow.frame = LFrame;
CGRect RFrame = rightArrow.frame;
RFrame.origin.x -= RFrame.size.width; // move it in from the right.
rightArrow.frame = RFrame;
[UIView commitAnimations];
}
- (void) horizontalPart2 {
// --------------------------------------------
// and animate them out
// delay enough for the first one to finish
[UIView beginAnimations:#"bar" context:nil];
[UIView setAnimationDelay: 1.0f ]; // in seconds
[UIView setAnimationDuration: 3.0f ];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDidStopSelector:#selector(horizontalAnimationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
CGRect LLFrame = leftArrow.frame;
LLFrame.origin.x -= LLFrame.size.width; // move it off to the left. // THIS IS NOT HAPPENING.
leftArrow.frame = LLFrame;
CGRect RFrame = rightArrow.frame;
RFrame.origin.x += RFrame.size.width;
rightArrow.frame = RFrame;
leftArrow.alpha = 0.0f;
rightArrow.alpha = 0.0f;
[UIView commitAnimations];
}