Repeating glow animation outside radius (like bulb glowing effect) - core-animation

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){
}];
}

Related

I want my image in xCode to fade in

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

UILabel animating frame change disregarding delay

I have a UILabel that I show / hide. I want to show the label, pause for a few seconds and hide it. This code ISN'T working. It removes the view as soon as the animation finished (instantly)
-(void) show
{
[UIView animateWithDuration:.5f delay:0.0f
options:UIViewAnimationOptionCurveEaseIn animations:^{
CGRect newFrame = CGRectMake(0.0f, 64.0f, [UIScreen mainScreen].bounds.size.width, 44.0f);
self.frame = newFrame;
} completion:^(BOOL finished){
[self hideAndRemove];
}];
}
-(void) hideAndRemove
{
[UIView animateWithDuration:.5f delay:2.0f
options:UIViewAnimationOptionCurveEaseIn animations:^{
CGRect frame = CGRectMake(0.0f, 64.0f, [UIScreen mainScreen].bounds.size.width, 0.0f);
self.frame = frame;
} completion:^(BOOL finished){
// nothing
}];
}
However, if I try some other animation on the frame, the delay works and the frame change is animated:
-(void) show
{
[UIView animateWithDuration:.5f delay:0.0f
options:UIViewAnimationOptionCurveEaseIn animations:^{
CGRect newFrame = CGRectMake(0.0f, 64.0f, [UIScreen mainScreen].bounds.size.width, 44.0f);
self.frame = newFrame;
} completion:^(BOOL finished){
[self hideAndRemove];
}];
}
-(void) hideAndRemove
{
[UIView animateWithDuration:.5f delay:2.0f
options:UIViewAnimationOptionCurveEaseIn animations:^{
CGRect frame = CGRectMake(0.0f, 64.0f, [UIScreen mainScreen].bounds.size.width, 250.0f);
self.frame = frame;
} completion:^(BOOL finished){
// nothing
}];
}
I don't know what the problem might be, but I think it comes from the frame height who shouldn't be set to 0.
Why not using [UILabel setAlpha:0] to hide your label, and [UILabel setAlpha:1] to show it back ? It seems cleaner than changing its frame height to 0, and it animates nicely.

How can I cover the entire iPhone screen with the keyboard being show?

Imagine a simple translucent mask that I'd like to cover the whole iphone screen:
UIView *maskView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];
maskView.backgroundColor = [UIColor blackColor];
maskView.alpha = 0.0f;
maskView.userInteractionEnabled = NO;
[[[UIApplication sharedApplication] keyWindow] addSubview:maskView];
[UIView animateWithDuration:.7 delay:.5f options:UIViewAnimationCurveEaseOut
animations:^{
maskView.alpha = .3f;
}
completion:^(BOOL finished) {
}];
However, the screen is displaying the keyboard ( I have made a textfiled in the view a first responder).
How can I cover the keyboard with my maskView?

How can I fade a UIView in while moving it up?

I have a UIView and I want to give it an effect that causes it to start with an alpha of 0 and then while moving up 50 pixels animated it also changes to an alpha of 1. How can this be done in Objective-C?
[UIView animateWithDuration:1.0 animations:^{
//here change position and alpha
CGRect newFrame = view.frame;
newFrame.origin.y += 50;
view.frame = newFrame;
view.alpha = 1.0;
} completion:^(BOOL finished) {
//called when animation did finish. do what you want
}];
https://developer.apple.com/library/ios/documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html
Everything about animations.
It's all right there.
//something similar to what you want:
- (IBAction)showHideView:(id)sender
{
// Fade out the view right away
[UIView animateWithDuration:1.0
delay: 0.0
options: UIViewAnimationOptionCurveEaseIn
animations:^{
thirdView.alpha = 0.0;
}
completion:^(BOOL finished){
// Wait one second and then fade in the view
[UIView animateWithDuration:1.0
delay: 1.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
thirdView.alpha = 1.0;
}
completion:nil];
}];
}
Something like this would do the trick:
UIView *box = [[UIView alloc] initWithFrame:CGRectMake(self.view.center.x, self.view.center.y, 100, 50)];
box.backgroundColor = [UIColor blackColor];
box.alpha = 0.0f;
[self.view addSubview:box];
[UIView animateWithDuration:2.0f
animations:^{
box.alpha = 1.0f;
CGRect frame = CGRectMake(self.view.center.x, self.view.center.y - 100, 100, 50);
[box setFrame:frame];
}];

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"]];
}];