I want my image in xCode to fade in - xcode6

I want my image to fade IN, not out. With this code, it's backwards. Any help?
[UIView animateWithDuration:3.0 animations:^{
self.circleOne.alpha = 0.0;
}];

If your circleOne has alpha 0(invisible) all you need to do is set the alpha to 1:
[UIView animateWithDuration:3.0 animations:^{
self.circleOne.alpha = 1.0;
}];
Edit:
If you want to make a animation before it appears on screen, you can set the alpha to 0 before adding the circleOne the it's parentview.
Assuming that circleOne is an UIImageView it would be like this:
circleOne = [[UIImageView alloc] initWithImage: [UIImage imageNamed:#"imageName,jpg"]];
circleOne.alpha = 0.0;
[parentView addSubview: circleOne];
//run the animation explained before

Related

Repeating glow animation outside radius (like bulb glowing effect)

I am working on iPad project and I need to do animation like glowing bulb with smooth ON/ OFF effect. How can I achieve this?
I tried with UIView animation and try to get same kind of animation.
Here is code which I tried.
-(void) setGlowToView{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake((self.frame.size.width-7.f)/2.f, (self.frame.size.height-7.f)/2.f, 7.f, 7.f)];
view.backgroundColor = [UIColor whiteColor];
[self addSubview:view];
[UIView animateWithDuration:1.5 delay:0.0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
view.alpha = 0.8;
view.layer.cornerRadius = 2.2;
view.transform = CGAffineTransformMakeScale(1.8,1.8);
} completion:^(BOOL finished){
}];
}

How to make images appear and disappear in iOS apps?

I'm trying to make my app show an image (PNG) in the middle of a screen when a button is pressed and then make it fade out after a few seconds. How would I be able to do this? Also it is a small png so how can i just make it show in its original size rather then stretch it out to fit the whole screen? Any tip, suggestion or answer is greatly appreciated!
Also I am new to this site so could you please tip me or help me improve this question as some people think it is not complete. Thank you everyone for your generous answers! :)
Initialize an UIImageView with an UIImage:
// Assuming MyImage.png is part of the project's resources.
UIImage *image = [UIImage imageNamed:#"MyImage.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
// Add imageView to a parent view here.
[UIView animateWithDuration:0.2f delay:3.0f options:0
animations:^{imageView.alpha = 0.0;}
completion:^{[imageView removeFromSuperview];}];
Here is the code for showing image for the few seconds on button press:
in your button action add following code:
imageView.image=yourImage;
[self performSelector:#selector(waitAndGo) withObject:nil afterDelay:5];
here is the implementation for the waitAndGo:
-(void)waitAndGo
{
imageView.hidden=YES;
}
NSArray *animationArray = [NSArray arrayWithObjects:[UIImage imageNamed:#"myImage.png"], nil];
[NSTimer scheduledTimerWithTimeInterval:.75 target:self selector:#selector(crossfade) userInfo:nil repeats:YES];
mainImageView.animationImages = animationArray;
mainImageView.animationDuration = 4.5; //mainImageView is instance of UIImageView
mainImageView.animationRepeatCount = 0;
[mainImageView startAnimating];
CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:#"contents"];
crossFade.autoreverses = YES;
crossFade.repeatCount = 1;
crossFade.duration = 1.0;
and the target method:
- (void) crossfade {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; // user dependent transition acn be set here
mainImageView.alpha = !mainImageView.alpha;
[UIView commitAnimations];
}

iOS Sliding Animation Happens Twice Unwantingly

I'm working on a page-based iPhone app using Xcode 4.4 with ARC and have been stuck on this for awhile. On a certain page, a UIImageView finger needs to slide up and point to something and then slide left off the screen. This works as expected when I run it once, but when I turn the page and go back - there is now 2 fingers sliding about 0.5 seconds out of sync with eachother.
Here's the code:
-(void)fingerSwipeUp:(UIImageView *)imageView
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[imageView setCenter:CGPointMake(213.75,355.5)];
[UIView commitAnimations];
}
-(void)fingerSwipeLeft:(UIImageView *)imageView
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[imageView setCenter:CGPointMake(-80,355.5)];
[UIView commitAnimations];
}
UIImageView *finger = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"finger.png"]];
// position finger off the screen
[finger setFrame:CGRectMake(142.5,480,152.5,243)];
[self.view addSubview:finger];
[self performSelector:#selector(fingerSwipeUp:) withObject:finger afterDelay:6];
[self performSelector:#selector(fingerSwipeLeft:) withObject:finger afterDelay:8];
Any help greatly appreciated
I'm guessing that you're creating the "finger" view in ViewDidAppear()? If that's the case, every time the page is turned (hidden) and then gone back to, you're adding another arrow (subview). What about this instead:
if (finger == nil) {
finger = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"finger.png"]];
[finger setFrame:CGRectMake(142.5,480,152.5,243)];
[self.view addSubview:finger];
}
[self performSelector:#selector(fingerSwipeUp:) withObject:finger afterDelay:6];
[self performSelector:#selector(fingerSwipeLeft:) withObject:finger afterDelay:8];
If you've got a number of animations in a sequence, you might find it easier to use the block-based UIView animation syntax:
[UIView animateWithDuration:1.0 delay:6.0 options:UIViewAnimationCurveEaseInOut animations:^{
// animation 1
} completion:^(BOOL finished) {
[UIView animateWithDuration:1.0 delay:8.0 options:UIViewAnimationCurveEaseInOut animations:^{
// animation 2
}];
}];
This will only start animation 2 after animation 1 has finished, so you don't need to worry about allowing for the duration of animation 1 when delaying animation 2.

Animated background in iOS

I want to animate my background after a view got loaded in my iOS application. This works with solid colors, but I'm not able to let it work using background images. This is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
[UIView animateWithDuration:5.0 animations:^{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background.png"]];
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background_dark.png"]];
}];
[UIView commitAnimations];
}
Does anyone know the correct way to do this?
Thanks
You animate things like this:
view.backgroundColor = INITIAL COLOR
[UIView animateWithDuration:5.0 animations:^{
view.backgroundColor = FINAL COLOR
}];
The animate method animates the change from the current state to whatever you set up in the animation block. The animation block is not a list of steps.
Therefore, I think what you want is this:
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background.png"]];
[UIView animateWithDuration:5.0 animations:^{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background_dark.png"]];
}];
Also, do NOT call commitAnimations afterward, that's only if you're using the old-style beginAnimations method. Read the documentation, and don't just call methods to see if they work.
Not all properties can be animated like this. It is very likely that a background image is one of them. What you can do is have a second view on top with the new image and animate its alpha from 0 to 1.
Ty this:
[UIView animateWithDuration:5.0 animations:^{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background.png"]];
} completion:^(BOOL finished)
{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background_dark.png"]];
}];

Get UITableviewCell position from "visible" area or window

I create an iPhone app base on uitableview and uitabbar. On each cell of tableview i have an "add to favorite button".
When i pressed this button, i want to make the cell "jump" from her position to the favorite item of the tabbar (same as download effect in installous)
The effect work well if i'am on top 10 cell, but if i scroll in the tableView the effect is not good because start position is calculate from uitableview size.
It's possible to know the position of a cell from the visible area. ?
Exemple : for the fortieth cell position is x:0,y:1600,w:320,y:50, i want the position from the top of the screen not from the top of the uiview so something like this x:0,y:230,w:320,y:50
Yes you can use rectForRowAtIndexPath: you'll just have to pass in the indexPath of your row you've clicked.
rectForRowAtIndexPath:
Returns the drawing area for a row
identified by index path.
...
EDIT
Conversion:
CGRect rectInTableView = [tableView rectForRowAtIndexPath:indexPath];
CGRect rectInSuperview = [tableView convertRect:rectInTableView toView:[tableView superview]];
So here is the code i used : (it can be optimized i'm sure) :
First add NSindexPath ** property to your custom cell.
*Implement this in your tableview controller : *
-(void)addCellToFavorisWithAnimation:(ResultSearchOffreCell*)cell{
/* Generate image from cell
----------------------------------------------------------*/
UIGraphicsBeginImageContextWithOptions(cell.bounds.size, cell.opaque, [[UIScreen mainScreen] scale]);
[cell.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Launch first animation (go to top-right)
//----------------------------------------------------------*/
CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:cell.indexPath];
CGRect rectInSuperview = [self.tableView convertRect:rectInTableView toView:[self.tableView superview]];
cellAnimationContainer = [[UIImageView alloc] initWithFrame:rectInSuperview];
[cellAnimationContainer setFrame:CGRectMake(cellAnimationContainer.frame.origin.x, cellAnimationContainer.frame.origin.y+50 , cellAnimationContainer.frame.size.width, cellAnimationContainer.frame.size.height)];
[cellAnimationContainer setImage:img];
AppDelegate_Shared *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.window addSubview:cellAnimationContainer];
[UIView beginAnimations:#"addFavorite-Step1" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:0.2];
[cellAnimationContainer setFrame:CGRectMake(20,cellAnimationContainer.frame.origin.y-10, cellAnimationContainer.frame.size.width, cellAnimationContainer.frame.size.height)];
[cellAnimationContainer setAlpha:0.7];
[UIView commitAnimations];
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
/* Launch second animation => go to favoris Tab and remove from self.view
---------------------------------------------------------------------------*/
if([anim isEqual:#"addFavorite-Step1"])
{
[UIView beginAnimations:#"addFavorite-Step2" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
[cellAnimationContainer setAlpha:0.4];
[cellAnimationContainer setFrame:CGRectMake(150, 420, 20, 20)];
[UIView commitAnimations];
}
else if([anim isEqual:#"addFavorite-Step2"])
{
[cellAnimationContainer removeFromSuperview];
[cellAnimationContainer release];
}
}
Yes this is possible like that
-(void)click:(id)sender
{
int clickcelltag;
clickcelltag=sender.tag;
NSIndexPath *index =[NSIndexPath indexPathForRow:clickcelltag inSection:0];
[userreviewtblview scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionTop animated:YES];//userreviewtblview is a UITableView name
}
Hope this will help you :-)