How to make image Disappear on touching it? - iphone

I am working on apllication for iphone in xcode 3.1.
I want similar two images to disappear when touched one after other.
I have succeed in displaying two images on iphone simulator on touching
'PlAY' button.
Now i want that when two same images are 'touched' one after another,they should disappear.
Expect code in Objective C.

You can do this, by using simple animations the view should disappear, later you can cast the context inside the UIView animations delegate and start a second animation.
aView.alpha = 1.0;
[UIView beginAnimations:nil context:#"Context1"];
[UIView setAnimationDuration: 1.0];
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
[UIView setAnimationBeginsFromCurrentState:YES];
aView.alpha = 0.0;
[UIView commitAnimations];
This id the delegate method you should implement:
-animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context

Related

Change Navigation Controller's Toolbar Animation in setToolbarHidden:animated:

I wanted to change the animation that occurs on a navigationControllers toolbar when the method setToolbarHidden is called. By default, when you set Hidden to YES and animation to YES, the toolbar simply drops off the screen. I'd like it to slide off the screen from left to right (much like when you hit the back button on a navbar and the previous view controller reasserts itself on the screen). Is this possible?
This isn't going to be perfect but it might be possible with something like this:
self.navigationController.toolbarHidden = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationFinished:finished:context:)];
CGRect frame = self.navigationController.toolbar.frame;
frame.origin.x = -1*frame.size.width;
self.navigationController.toolbar.frame = frame;
[UIView commitAnimations];
- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context {
self.navigationController.toolbarHidden = YES;
}
I filed a bug report and it appears, unfortunately, there isn't a way to do this until Apple adds the feature themselves.

Repeat beginAnimations -- All Animations

I'm making a simple image rotator by fading in and out 4 different images. It works great, until the end, when I want all four animations to repeat.
I've tried the repeat count, but that will only apply to that one specific animation. How do I create an entire loop?
My code is below. Thanks in advance!
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:slideshow cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:3];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationDelay:3];
imageOne.alpha = 0;
imageTwo.alpha = 1;
[UIView setAnimationDelay:6];
imageTwo.alpha = 0;
imageThree.alpha = 1;
[UIView setAnimationDelay:9];
imageThree.alpha = 0;
imageFour.alpha = 1;
[UIView commitAnimations];
You can start by putting a name to your animations so instead of beginAnimations:nil, you'd put beginAnimations: #"Button Animations" or something like that. Also, you should set the delegate of the animation to self. This can be done by adding the following line of code into your animation block:
[UIView setAnimationDelegate: self];
Then you can put this whole entire animation block into a class method of it's own (in your view controller). Lets call it doAnimation. This is just for safe measure. the next thing you should do is implement this delegate function in your view controller:
-(void) animationDidStop: (NSString *) animationID finished:(NSNumber *)finished context:(void *)context{
if([animationID isEqualToString:#"Button Animation"]){
[self doAnimation];
}
}
So pretty much this will ensure that your animations will repeat. If this method doesn't work, let me know, I didn't test it. But I think it'll work.

iOS: After one animation, all other views start animating

I have a very peculiar problem. In an iOS app I've developed, after running the animations below I find that various other elements of the UI now animate whenever they appear.
For instance, once these animations below are run, every time I navigate to a new tab in my app, all the UI elements animate from the top left corner of the iphone to their proper positions. I have specified no animations for these UI elements in the other tabs and in fact even elements that I have no access to, like the activity indicator in the iPhone status bar, begin to animate all on their own.
What is going on? Why does this occur only after the animation below is executed? Before running this animation (with a button press) all other UI elements in other app tabs do not animate at all when they appear, which is the expected behaviour.
- (IBAction) btnChosenPostcodeClicked:(id)sender {
//prep animations
startView.alpha = 1.0;
postcodeView.alpha = 0.0;
[self.view addSubview:postcodeView];
[UIView beginAnimations:#"ChosenPostcodeAnimation01" context:nil];
[UIView setAnimationDuration:animationSpeed];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(chosenPostCodeFadeoutAnimationDone:finished:context:)];
startView.alpha = 0.0;
[UIView commitAnimations];
}
- (void)chosenPostCodeFadeoutAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
//prep animations
postcodeView.alpha = 0.0;
[UIView beginAnimations:#"ChosenPostcodeAnimation02" context:nil];
[UIView setAnimationDuration:animationSpeed];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
CGRect newRect = CGRectMake(42, 157, 239, 180);
imvBubble.frame = newRect;
postcodeView.alpha = 1.0;
}
You're missing a
[UIView commitAnimations];
in chosenPostCodeFadeoutAnimationDone so absolutely everything you do is becoming part of the animation!

How can I use this animation code?

I'm a newbie and I need some help.
I want to display a popup image over a given UIView, but I would like it to behave like the UIAlertView or like the Facebook Connect for iPhone modal popup window, in that it has a bouncy, rubbber-band-like animation to it.
I found some code on the net from someone who was trying to do something similar. He/she put this together, but there was no demo or instructions.
Being that I am so new, I don't have any idea as to how to incorporate this into my code.
This is the routine where I need the bouncy image to appear:
- (void) showProductDetail
{
. . .
////////////////////////////////////////////////////////////////////////
// THIS IS A STRAIGHT SCALE ANIMATION RIGHT NOW. I WANT TO REPLACE THIS
// WITH A BOUNCY RUBBER-BAND ANIMATION
_productDetail.transform = CGAffineTransformMakeScale(0.1,0.1);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
_productDetail.transform = CGAffineTransformMakeScale(1,1);
[UIView commitAnimations];
}
. . .
}
This is the code I found:
float pulsesteps[3] = { 0.2, 1/15., 1/7.5 };
- (void) pulse {
self.transform = CGAffineTransformMakeScale(0.6, 0.6);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:pulsesteps[0]];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(pulseGrowAnimationDidStop:finished:context:)];
self.transform = CGAffineTransformMakeScale(1.1, 1.1);
[UIView commitAnimations];
}
- (void)pulseGrowAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:pulsesteps[1]];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(pulseShrinkAnimationDidStop:finished:context:)];
self.transform = CGAffineTransformMakeScale(0.9, 0.9);
[UIView commitAnimations];
}
- (void)pulseShrinkAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:pulsesteps[2]];
self.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
}
Thanks in advance for any help that you can give me.
It's pretty simple. In your showProductDetail method, you start an animation block, then set the _productDetail.transform property, and then commit the block. This is what makes the animation happen.
The code that you found is designed to do a chain of such animations, but the property being modified is on self instead of on _productDetail. If _productDetail is an instance of a class that you created yourself, you can put the animation code inside that class.
Otherwise, just move the code inside the pulse method to the showProductDetail method, and put the two other methods below that method. Replace self.transformwith _productDetail.transformin all three methods.

How to make iPhone screen dim

I have a refresh button on my iphone screen that refreshes a table in the current view.
The screen refresh beautifully, but is there a way I can make the screen dim and then lighten again after the table has refreshed?
You could place a non-opaque view with a black background over the view you wish to dim. This would have an alpha value of 0 by default and thus be transparent. You could then use a UIView animation to set the black views alpha from 0 to 0.5 (say) and then back.
Note: The code below has not been tested but I have used similar to achieve the same effect.
...
dimView.alpha = 0.0f;
[UIView beginAnimations#"fade" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView setAnimationRepeatAutoreverses:YES];
dimView.alpha = 0.5f;
[UIView commitAnimations];
...
}
- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
dimView.alpha = 0.0f;
}
Could you load a black, 50% alpha view over the top, possibly fade in?