I want to create a custom alertView that works like instagram app (login/signin view when user enters wrong password or email). The alert animation should drop down and pause for the user to read for about 2 seconds, then the alertView goes up again. How can I do this?
Here is what I have now:
- (UIView *) createAlertViewWithViewController:(UIViewController *)viewController andText:(NSString *)alertText
{
alertView = [[UIView alloc] init];
[alertView setBackgroundColor:ALERT_VIEW_COLOR];
[alertView setFrame:ALERT_VIEW_HIDE_FRAME];
UILabel *alertViewLabel = [[UILabel alloc] init];
[alertViewLabel setFrame:CGRectMake(viewController.view.bounds.origin.x, 7, viewController.view.bounds.size.width, ALERT_VIEW_HEIGHT)];
[alertViewLabel setTextAlignment:NSTextAlignmentCenter];
[alertViewLabel setTextColor:[UIColor whiteColor]];
[alertViewLabel setFont:[UIFont systemFontOfSize:13.0f]];
[alertViewLabel setText:alertText];
[alertView addSubview:alertViewLabel];
CGPoint originalCenter = alertView.center;
[UIView animateWithDuration:0.5
animations:^{
CGPoint center = alertView.center;
center.y += ALERT_VIEW_HEIGHT;
alertView.center = center;
}
completion:^(BOOL finished){
[UIView animateWithDuration:3.0
animations:^{
alertView.center = originalCenter;
}
completion:^(BOOL finished){
;
}];
}];
return alertView;
}
My code right now goes down and goes up immediately but what I want is, when it finishes the drop down animation it pauses for around 2 seconds then do the goes up animation.
I have been searching for 3 days now, but I haven't found anything one this.
Example image when it should pause for 2 seconds:
Im guessing you are looking for one of the extended versions of [UIView animateWithDuration:...
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
Pass in a delay to wait your animation.
Would you like a this library?
https://github.com/problame/CSNotificationView
Example
[CSNotificationView showInViewController:self
tintColor:[UIColor colorWithRed:0.000 green:0.6 blue:1.000 alpha:1]
image:nil
message:#"What's the meetup called?"
duration:2.f];
Try this:
UILabel *myLable=[[UILabel alloc]init];
myLable.frame=CGRectMake(0, -50, 320, 50);
myLable.backgroundColor=[UIColor grayColor];
myLable.textAlignment=NSTextAlignmentCenter;
myLable.text=#"Your Error Message";
[self.view addSubview:myLable];
[self ShowAnimation:myLable currentFrame:CGRectMake(0, -50, 320, 50) newFrame:CGRectMake(0, 0, 320, 50)];
.
-(void)ShowAnimation:(UILabel *)aLable currentFrame:(CGRect)aCurrentFrame newFrame:(CGRect)aNewFrame
{
[aLable setFrame:aCurrentFrame];
[UIView animateWithDuration:1.5 animations:^{
[aLable setFrame:aNewFrame];
}completion:^(BOOL finished)
{
[aLable setFrame:aNewFrame];
[UIView animateWithDuration:1.5 delay:2.0 options:UIViewAnimationOptionCurveEaseIn
animations:^{
[aLable setFrame:aCurrentFrame];
}
completion:^(BOOL finished) {
}];
}];
}
Related
I am trying animate and get transferred only when the animation gets finished..but everything works fine except the segue...when I clicked the button it navigates to another page...before the animation gets finished... I a new bee to ios please mention my mistake...
#import "ViewController.h"
#import <Lottie/lottie.h>
#interface ViewController ()
#property UIView * AnimatedViewForLoading;
#property LOTAnimationView * LottieAnimationHourGlass;
#end
-(IBAction)ButtonTouched:(id)sender {
self.AnimatedViewForLoading = [[UIView alloc] initWithFrame:CGRectMake(118, 318, 200, 150)];
[self.AnimatedViewForLoading setBackgroundColor:[UIColor clearColor]];
// self.AnimatedViewForLoading.alpha = 0.0f;
//AnimatedViewForLoading.backgroundColor = UIColor.lightGrayColor;
self.LottieAnimationHourGlass = [LOTAnimationView animationNamed:#"hourglass"];
self.LottieAnimationHourGlass.frame = CGRectMake(118, 318, 200, 150);
// if(!UIAccessibilityIsReduceTransparencyEnabled()){
// self.view.backgroundColor = [UIColor clearColor];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *blureffectview = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
blureffectview.frame = self.view.bounds;
blureffectview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:blureffectview];
[self.view insertSubview:_AnimatedViewForLoading aboveSubview:blureffectview];
//[self.view sendSubviewToBack:_AnimatedViewForLoading];
[self.view insertSubview:_LottieAnimationHourGlass aboveSubview:_AnimatedViewForLoading];
[_LottieAnimationHourGlass play];
_LottieAnimationHourGlass.loopAnimation = YES;
// }else{
//self.view.backgroundColor = [UIColor blackColor];
// }
self.AnimatedViewForLoading.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:10.0 delay:3.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.AnimatedViewForLoading.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished) {
NSLog(#"oopssssss..........");
[UIView animateWithDuration:0.3/2 animations:^{
self.AnimatedViewForLoading.transform = CGAffineTransformIdentity;
}];
if (finished == true) {
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:#"YourTimeisLoading" sender:_AnimatedViewForLoading];
}
}];
//[self dismissViewControllerAnimated:YES completion:nil];
}
scenario 1:
check your second completion
[UIView animateWithDuration:10.0 delay:3.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.AnimatedViewForLoading.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished) {
NSLog(#"oopssssss..........");
[UIView animateWithDuration:0.3/2 animations:^{
self.AnimatedViewForLoading.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:#"YourTimeisLoading" sender:_AnimatedViewForLoading];
}];
}];
scenario 2:
ensure once your performSegueWithIdentifier is connected with VC not directed in button.If its directly connected with your UIButton,it won't consider anything inside the action handler.
Im trying to fade in and out of a light node I have created I just dont know where to call the function accordingly so it will continously fade in and out. Never tried animating anything here is what I have.
- (void)fadeOutIn:(UIView *)view duration:(NSTimeInterval)duration
{
[self enumerateChildNodesWithName:#"//*" usingBlock:^(SKNode *node, BOOL *stop) {
if ([node.name isEqualToString:#"light1"]) {
[UIView animateKeyframesWithDuration:5 delay:2 options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse|UIViewAnimationCurveEaseInOut animations:^{
node.alpha = 0;
} completion:^(BOOL finished) {
}];
}
}];
}
where should I call this function?that is fades in and out continously?
Should it be called within an action?
Thank You
Use this for Continue fade in out.
-(void)viewDidAppear:(BOOL)animated{
[UIView animateKeyframesWithDuration:1 delay:0 options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse|UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^{
node.alpha = 0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1 animations:^{
node.alpha = 1;
} completion:nil];
}];
}
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[objAnimate setAlpha:1.0];
[UIView animateKeyframesWithDuration:2.0 delay:0.0 options:UIViewKeyframeAnimationOptionCalculationModeLinear | UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse animations:^{
[objAnimate setAlpha:0.0];
} completion:nil];
}
This will create continuous fade in and out for your object when it appears. If you want to create programmatically a custom object and then use this code then do it after your custom object is added in your view as below (example):
objAnimate = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, 200, 40)];
objAnimate.backgroundColor = [UIColor lightGrayColor];
[objAnimate setAlpha:1.0];
[self.view addSubview:objAnimate];
[UIView animateKeyframesWithDuration:2.0 delay:0.0 options:UIViewKeyframeAnimationOptionCalculationModeLinear | UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse animations:^{
[objAnimate setAlpha:0.0];
} completion:nil];
The view starts animating as soon as its added in your view.
I have created an animation. This animation is a button.
But when I touch this button, nothing appears.
I have activated the option :
UIViewAnimationOptionAllowUserInteraction
This is my animation's code :
[UIView animateWithDuration:1.5
delay:0
options:(UIViewAnimationOptionAllowUserInteraction)
animations:^{
btnRock.center = CGPointMake(btnRock.center.x - 450, btnRock.center.y - positionY);
}completion:^(BOOL finished){
btnRock.center = CGPointMake(btnRock.center.x + 450, btnRock.center.y + positionY+ positionYBase);
[self play];
}];
And this is my button's code :
-(IBAction)touchRock:(id)sender{
cptScore++;
score.text = [[NSString alloc] initWithFormat: #"%.d", cptScore];
}
I am displaying popped up a view by zoom in zoom out effect. When my app will return from safari after login wtih facebook I am displaying that view. This is working fine in simulator. But it is not working in device. I am checking that thing in ipad . Here is my code:
[MyAppDelegate openSessionWithAllowLoginUI:YES completionBlock:^(BOOL result) {
NSLog(#"Connecte via Joint Page Thank you");
if (result) {
NSLog(#"%# %d ", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation],[[[NSUserDefaults standardUserDefaults] valueForKey:#"isSender"]boolValue]);
if([[[NSUserDefaults standardUserDefaults] valueForKey:#"isSender"]boolValue]==0 && [[[NSUserDefaults standardUserDefaults] valueForKey:#"isServiceProvider"] boolValue]==0){
lbl_register.font=[UIFont fontWithName:GZFont size:16];
lbl_serviceProvider.font=[UIFont fontWithName:GZFont size:14];
lbl_customer.font=[UIFont fontWithName:GZFont size:14];
SelectionView.center=self.view.center;
SelectionView.layer.borderColor=[[UIColor blackColor] CGColor];
SelectionView.layer.borderWidth=1.0;
SelectionView.layer.cornerRadius=5;
SelectionView.layer.masksToBounds=YES;
[UIView animateWithDuration:0.4 animations:^{
SelectionView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished) {
NSLog(#"popped");
SelectionView.center=self.view.center;
[UIView animateWithDuration:0.4 animations:^{
SelectionView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.95,0.95);
} completion:^(BOOL finished) {
// self.view.userInteractionEnabled=NO;
}];
}];
[self.view addSubview:SelectionView];
You try this code
explodedBackgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
explodedView = [[UIView alloc]init];
explodedView.frame = CGRectMake(10, 10, 540, 120);
[explodedBackgroundView setFrame:self.view.bounds];
explodedView.center=CGPointMake(self.view.center.x, self.view.center.y);
[explodedBackgroundView setBackgroundColor: [UIColor blackColor]];
[explodedBackgroundView setAlpha: 0.5];
[self.view addSubview:explodedBackgroundView];
explodedView.layer.cornerRadius=20;
explodedView.transform = CGAffineTransformMakeScale(0.1, 0.1);
UIImageView *imageView=[[UIImageView alloc]initWithFrame:explodedView.bounds ];
[explodedView addSubview:imageView]
[self.view addSubview:explodedView];
explodedView.transform = CGAffineTransformMakeScale(0.1, 0.1);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
explodedView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
// do something once the animation finishes, put it here
}];
UPDATED
I want to make running text line, which way is better to make it?
-(void)viewDidLoad
{
CGSize mySize = CGSizeZero;
mySize = [kGrindFMRunningText sizeWithFont:[UIFont fontWithName:#"Verdana" size:16] constrainedToSize:CGSizeMake(4000, 30) lineBreakMode:UILineBreakModeWordWrap];
runningText = [[UIScrollView alloc] initWithFrame:CGRectMake(60, -5, 260, 50)];
grind_fm_text = [[UILabel alloc] initWithFrame:CGRectMake(0, 15, mySize.width, 30)];
[grind_fm_text setUserInteractionEnabled:NO];
[grind_fm_text setBackgroundColor:[UIColor clearColor]];
[grind_fm_text setTextColor:[UIColor whiteColor]];
[grind_fm_text setFont:[UIFont fontWithName:#"Verdana" size:16]];
[grind_fm_text setText:kGrindFMRunningText];
[runningText addSubview:grind_fm_text];
[grind_fm_text release];
[self animate];
}
- (void)animate
{
[UIView animateWithDuration:10.0 delay:0. options:UIViewAnimationOptionCurveLinear|UIViewAnimationOptionBeginFromCurrentState animations:^{
grind_fm_text.frame = CGRectMake(-grind_fm_text.frame.size.width, 15, grind_fm_text.frame.size.width, grind_fm_text.frame.size.height);
// Do your animation in one direction until text is gone
} completion:^(BOOL finished){
grind_fm_text.frame = CGRectMake(260, 15, grind_fm_text.frame.size.width, grind_fm_text.frame.size.height);
// Move scroll position back to original position
[self animate]; // Then call animate again to repeat
}];
}
-(void)songChange
{
CGSize mySize = CGSizeZero;
mySize = [result sizeWithFont:[UIFont fontWithName:#"Verdana" size:16] constrainedToSize:CGSizeMake(4000, 30) lineBreakMode:UILineBreakModeWordWrap];
grind_fm_text.frame = CGRectMake(grind_fm_text.frame.origin.x, 15, mySize.width, 30);
grind_fm_text.text = result;;
[self animate];
}
- (void)startStopStream {
[streamer stop];
//[bufferIndicator stopAnimating];
[CATransaction begin];
[self.view.layer removeAllAnimations];
[CATransaction commit];
grind_fm_text.text = kGrindFMRunningText;
CGSize mySize = CGSizeZero;
mySize = [kGrindFMRunningText sizeWithFont:[UIFont fontWithName:#"Verdana" size:16] constrainedToSize:CGSizeMake(4000, 30) lineBreakMode:UILineBreakModeWordWrap];
grind_fm_text.frame = CGRectMake(grind_fm_text.frame.origin.x, 15, mySize.width, 30);
[self animate];
}
[CATransaction begin]; [myView.layer removeAllAnimations]; [CATransaction commit]; doesn't work for me. UIViewAnimationOptionCurveLinear|UIViewAnimationOptionBeginFromCurrentState works strangely: first, it doesn't do completion block as i see, or maybe it does, but animation doesn't start again. And If i click button nothing happening, but when i click it second time, animation begins from another direction and slows until freeze.
You should be able to do this more simply with nested UIView animation blocks. In the animation block have it scroll in the one direction, in the completion block have it scroll in the other direction and in that animation's completion block have it call your animate function over again so it repeats.
Something like this:
- (void)animate
{
[UIView animateWithDuration:10.0 delay:0. options:UIViewAnimationOptionCurveLinear animations:^{
// Do your animation in one direction
} completion:^(BOOL finished){
[UIView animateWithDuration:10.0 delay:0. options:UIViewAnimationOptionCurveLinear animations:^{
// Do your animation in the other direction
} completion:^(BOOL finished){
[self animate];
}];
}];
}
Or if you want it to scroll all the way across then do it again, something like:
- (void)animate
{
[UIView animateWithDuration:10.0 delay:0. options:UIViewAnimationOptionCurveLinear animations:^{
// Do your animation in one direction until text is gone
} completion:^(BOOL finished){
// Move scroll position back to original position
[self animate]; // Then call animate again to repeat
}];
}
It sounds like by default, animations use the UIViewAnimationOptionCurveEaseInOut animation option. You want the UIViewAnimationOptionCurveLinear option. I've updated my code above to include that.
As per an answer to this question: Cancel a UIView animation? you should be able to cancel the animation by calling [myView.layer removeAllAnimations]; where myView is the scroll view being animated. Make sure to import <QuartzCore/QuartzCore.h> at the top to access CALayer methods.
Edit: you may need to call it like this to make sure it runs immediately and not after the next runloop iteration:
[CATransaction begin];
[myView.layer removeAllAnimations];
[CATransaction commit];
Or if that still doesn't work, then likely just changing the options parameters in the UIView method calls to UIViewAnimationOptionCurveLinear|UIViewAnimationOptionBeginFromCurrentState should work, with no need to call removeAllAnimations. In fact, try that first.