views:

68

answers:

3

I've got an NSArray setup in my code to display two PNG's alternately flashing, I'm trying to setup a piece of code that sets it to a hidden status, moves it off screen, anything to get it out of sight of the user.

The code for my array is

NSArray *imageArray = [[NSArray alloc] initWithObjects:
 [UIImage imageNamed:@"CONNECTED dark yellow FF CC 00.png"],
 [UIImage imageNamed:@"CONNECTEDR dark yellow FF CC 00.png"], nil];

UIImageView *animation = [[UIImageView alloc] initWithFrame: CGRectMake(20, 10, 300, 80)];
animation.animationImages = imageArray;
animation.animationDuration = .8;
animation.contentMode = UIViewContentModeBottomLeft;
[self.view addSubview:animation];
[animation startAnimating];
[animation release];
[view release];

However if I try using a setHidden or .hidden:YES it doesn't seem to hide and cries out that animation is not declared. Can anyone suggest the answer to this? Sure its staring me slap bang in the face but after a few hours of trying? I've admitted defeat for now.

A: 

Have you tried setting the alpha property on your animation UIImageView to zero? If you modify this property inside an animation block, it will do an animated fade out.

Cannonade
+1  A: 

hidden is not animate-able, as there is no animation possible between YES and NO. There is no way to express "A bit YES and a bit NO" in boolean logic.

Try using alpha instead

[aView setAlpha:1.0] // fully opaque
[aView setAlpha:0.0] // fully transparent
vikingosegundo
To this, and Cannonade's answers - doesn't Alpha just alter transparency? If so I can't use this unfortunately as I actually need to remove this from the screen essentially as it overlays where a button will appear.
David26th
Views with alpha below approximately 0.1 do not receive touch events by default.
tc.
Thanks. Have tried this and suspect it to work however I still have an issue of animation not being declared.
David26th
+1  A: 

You have to keep a reference to the animation view (add a member/property to your view controller and add a code like _animationView = animation right before releasing it; and then use the _animationView instead of animation when trying to hide it).

Or you might set a tag to this view and find it by tag later...

I hope that I've understood your problem right - let me know otherwise.

EDIT (after your first response):

In MyViewController.h file:

class MyViewController : UIViewController {
    UIImageView *_animationView;
}

In MyViewController.m file:

NSArray *imageArray = [[NSArray alloc] initWithObjects:
 [UIImage imageNamed:@"CONNECTED dark yellow FF CC 00.png"],
 [UIImage imageNamed:@"CONNECTEDR dark yellow FF CC 00.png"], nil];

UIImageView *animation = [[UIImageView alloc] initWithFrame: CGRectMake(20, 10, 300, 80)];
animation.animationImages = imageArray;
animation.animationDuration = .8;
animation.contentMode = UIViewContentModeBottomLeft;
[self.view addSubview:animation];
[animation startAnimating];

// Add the next line
_animationView = animation;

[animation release];
[view release];




// Use this method to hide the animation view...
- (void)hideAnimationView {
    _animationView.hidden = YES;
    [_animationView stopAnimating];
}

EDIT 2:
Changed the declaration line in .h file (UIImageView *_animationView;)

Michael Kessler
Ok I think I get your general meaning here, but any chance you can sample me some code in to show what you mean more precisely? I think you're on the right idea for what I want but I don't often progrmatically build my views so I'm a tad confused by it all right now.
David26th
I have edited my answer. See if it helps...
Michael Kessler
error: statically allocated instance of Objective-C class 'UIView'Receive that in the .h
David26th
UIView _animationView; -> UIView *_animationView;
vikingosegundo
See my second edit...
Michael Kessler
You my friend win the green tick for the day :) I would just ask that you edit the line _animationView = animation to _animationView = animation; for future readers. Thank you.
David26th
:) Changed. I have written the code without the XCode...
Michael Kessler
Yeah it's brill. I figured it needed one but someone else might not so thought it a good idea to point out.
David26th